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

2
  • You'll need to set headers in your php file to prevent the browser from caching it automatically. Feb 18, 2011 at 19:48
  • It wasn't cached before? But thanks I'll try that.
    – Baversjo
    Feb 18, 2011 at 20:09

3 Answers 3

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.

2
  • 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, 2011 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, 2011 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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.