1

I am trying to load an application built using angularjs and salesforce with offline capabality. For this functionality i am using Offline Caching Using the HTML5 manifest Attribute provided by salesforce.

I have created a CACHE-MANIFEST file as:

    <apex:page contentType="text/cache-manifest" applyHtmlTag="false" standardStylesheets="false" showHeader="false">
CACHE MANIFEST

# Resources that require the user to be online.
NETWORK:
*

CACHE:
{!URLFOR($Resource.Bootstrap, 'css/bootstrap.min.css')}
{!URLFOR($Resource.Stylesheet, 'main.css')}
{!URLFOR($Resource.Stylesheet, 'ng-table.min.css')}
https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
{!URLFOR($Resource.Bootstrap, 'js/bootstrap.min.js')}    
{!URLFOR($Resource.AngularJSLib, 'angular.min.js')}
{!URLFOR($Resource.AngularJSLib, 'angular-route.min.js')}
{!URLFOR($Resource.AngularJSLib, 'angular-resource.min.js')}
{!URLFOR($Resource.AngularJSLib, 'ui-bootstrap-tpls-0.11.0.js')}
{!URLFOR($Resource.AngularApp,'app/directives/ngTable.js')}
{!URLFOR($Resource.AngularApp,'app/script/common.js')}
{!URLFOR($Resource.AngularApp,'app/controllers/technicianWOController.js')}
{!URLFOR($Resource.AngularApp,'app/controllers/technicianWOListController.js')}
{!URLFOR($Resource.AngularApp,'app/controllers/navController2.js')}
{!URLFOR($Resource.AngularApp,'app/app.js')}
{!URLFOR($Resource.AngularApp,'app/script/common.js')}
{!URLFOR($Resource.AngularApp,'app/views/technicianWorkOrder.html')}
{!URLFOR($Resource.AngularApp,'app/views/technicianWorkOrderGrid.html')}
{!URLFOR($Resource.AngularApp,'app/services/workOrderSVC.js')}
{!URLFOR($Resource.AngularApp,'app/controllers/DenyReasonPopupController.js')}
{!URLFOR($Resource.Bootstrap, 'js/bootstrap.min.js')}
{!URLFOR($Resource.Stylesheet,'Images/sprite-workorder.png')}

 </apex:page>

I have referred the same in my main VF page as:

<apex:page controller="WorkOrderControllerExtension"  docType="html-5.0"  manifest="/apex/CacheManifestVF"
 sidebar="false" showHeader="false" standardStylesheets="false">

I am getting the following error:

Application Cache Error event: Failed to parse manifest and "the path of VF page"

What may be the problem?

2 Answers 2

2

So, while I was writing up code that demonstrates this, I found that Salesforce now includes a "view state" script that I couldn't figure out how to bypass. Thankfully, we can use # to cause the manifest parser to ignore the line. Here's the code I came up with:

<apex:page readOnly="true" standardStylesheets="false" showChat="false" contentType="text/cache-manifest" showHeader="false" 
           applyBodyTag="false" applyHtmlTag="false">CACHE MANIFEST
/apex/MyPage
#</apex:page>

A few notes here to make sure everything turns out okay. First, the CACHE MANIFEST line must appear immediately after the apex:page's closing >, just to make sure that an errant blank line won't appear in front of the output.

Secondly, I included a # to force Visualforce into commenting out the extra code it insists on outputting. If anyone has a solution that doesn't involve commenting, I'd appreciate it if they added that information here.

The resulting output is as follows:

CACHE MANIFEST
/apex/MyPage
#<script type="text/javascript">  SfdcApp.Visualforce.viewstate.ViewstateSender.sendViewstate('https://na9.salesforce.com', 'cacheManifest');  </script>
2

The problem is that it is hard/impossible to stop Visualforce from outputting extra content. For example this:

<apex:page contentType="text/cache-manifest" applyHtmlTag="false" standardStylesheets="false" showHeader="false">
CACHE MANIFEST
abc.txt
</apex:page>

produces this output:

<html>
    <head></head>
    <body style="">
        <pre style="word-wrap: break-word; white-space: pre-wrap;">
CACHE MANIFEST
abc.txt</pre>
        <div id="window-resizer-tooltip"><a href="#" title="Edit settings"></a><span class="tooltipTitle">Window size: </span><span class="tooltipWidth" id="winWidth"></span> x <span class="tooltipHeight" id="winHeight"></span><br><span class="tooltipTitle">Viewport size: </span><span class="tooltipWidth" id="vpWidth"></span> x <span class="tooltipHeight" id="vpHeight"></span></div>
    </body>
</html>

instead of just this which is what the content type requires:

CACHE MANIFEST
abc.txt

Using a static resource instead would give you full control of the content, but you would have to hard-code paths to the static resources; leaving out the resource version number might work but you would need to experiment. (You can get the sort of path needed by viewing the output of the failing Visualforce page.)

11
  • Even if i comment all resource path and just keep <apex:page> tag it gives the same error see below: <apex:page contentType="text/cache-manifest" applyHtmlTag="true" standardStylesheets="false" showHeader="false"> CACHE MANIFEST </apex:page>, Do you think i am missing something?
    – Ejaz
    Commented Mar 10, 2016 at 15:02
  • @Ejaz That is the point I was trying to make to you above: the <html><head>... etc is emitted whether you want it or not.
    – Keith C
    Commented Mar 10, 2016 at 15:04
  • There's two extra attributes you need to use: applyHtmlTag and applyBodyTag. They should both be set to false. It's perfectly possible to get plain text output, you just have to ask for it.
    – sfdcfox
    Commented Mar 10, 2016 at 15:14
  • @sfdcfox That sounds like an answer you should post...
    – Keith C
    Commented Mar 10, 2016 at 15:59
  • @Ejaz See sfdcfox's solution just above.
    – Keith C
    Commented Mar 10, 2016 at 16:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .