Baversjo
Baversjo

Reputation: 3716

HTML5 cache manifest no cache for html file itself

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

Upvotes: 10

Views: 4434

Answers (3)

Kyle
Kyle

Reputation: 31

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

Upvotes: 0

Arney
Arney

Reputation: 81

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

Upvotes: 1

robertc
robertc

Reputation: 75707

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.

Upvotes: 13

Related Questions