HTML5 Software Cache Expiration

I have an HTML5 application that uses offline caching with a manifest file. The only way that triggers a cache update is to modify the manifest file on the server. I am looking for a software way to expire the cache and provide an update.

I looked at the spec, looking for some method on window.applicationCache to expire the cache. But did not find. There is an update () method, but it will only be updated if the cache has expired (i.e. there is a change in the manifest file). So it does not help.

Does anyone know a software way to expire application cache and force download?

+7
source share
2 answers

AFAIK, manifest is the only means of initiating an update. There is an article on the HTML5 Rocks website that talks about programmatically updating the cache (after updating manifest ) by immediately calling applicationCache.swapCache() after listening to the UPDATEREADY state in appCache.status .

I'm not sure this will be enough, but its a good read (scroll down to "Cache Update") - http://www.html5rocks.com/tutorials/appcache/beginner/

+2
source

It is true that an update is only triggered by an "updated" manifest file. But some browsers (FF, chrome) do not check all the files referenced by the manifest file. For example, jpg will not check if the server has a newer one. It appears that the general browser caching policy affects the update process. To force the browser to check all or some of the files in the cache manifest, you must mark these files with "Cache-Control: no-cache" in the HTTP header.

You can control the update operation using cookies. If you have a serveride script that interprets cookie commands, you can make the browser expire the contents of the cache through javascript. For example, if a client executes cache.update () with a set of cache_clear cookies, the server may respond with a response code 404, which causes the browser to expire the contents of the application cache.

+2
source

All Articles