10

index.php:

<html manifest="/cache.manifest">

cache.manifest

CACHE MANIFEST

CACHE:

/img.png
FALLBACK:
/ /offline.html
NETWORK:
*

Everything works great, except that the index.php file itself is fetched to cache (tested in chrome). Can I disable caching for the file specifying the manifest so that only the img.png is cached?

Thanks

Baversjo
  • 3,656
  • 3
  • 34
  • 47

3 Answers3

13

No, the file which references the manifest is always itself cached. From the spec:

The resource that declares the manifest (with the manifest attribute) will always get taken from the cache, whether it is listed in the cache or not, even if it is listed in an online whitelist namespace.

robertc
  • 74,533
  • 18
  • 193
  • 177
  • hey just to be clear - if I have a one-page web app & I use CACHE MANIFEST, I can not get around the page being cached? Cause there are various elements to be pushed into the dom upon certain user interactions and that is not available upon load the first time. – iUsable Sep 28 '11 at 16:28
  • 1
    @iUsable I'm not sure I can be more clear than I've already been, the file which references the manifest is always itself cached. If you're using script to add things to the page, then the script will still add things to the page when it's cached. If you need to fetch those things from a server then you need to look at LocalStorage to make them available offline. – robertc Sep 28 '11 at 17:06
1

I had the same problem.

I used an iframe to load a page called 'go_offline.html' this page has the manifest attribute on the html element and some dummy content.

the iframe is hidden using css

this way only the dummy page is cached and all requests are caught by the fallback page in the .manifest file

Arney
  • 81
  • 1
  • 2
0

I have tried the iframe work around, and find it ripe with errors. Most browsers cache the data for the iframe where the page cannot get it.

Instead make the page's content load via AJAX. Basically have a blank html page with the manifest and javascript which pulls and adds its content from the server. This way only the blank html is cached, and content is always updated from the server.

Converting a page to this method can be very difficult, but it works. Making sure the appropriate javascript gets run at the correct time, probably requires some detangling. Moving around server code which won't be called when pulling from cache to the new ajax method.

Note: no need to pull conditional content from the server if the condition is in the query string, different query strings make a separate cache

Kyle
  • 31
  • 3