HTML5 offline cache programmatic expiration
I have an HTML5 app that uses offline caching with a manifest file. The only way that triggers the updating of cache is a change in the manifest file on server. I am looking for a programmatic way of expiring the cache and enforcing update.
I went through the spec, looking for some method on window.applicationCache to expire the cache. But didn't find any. There is an update() method, but it will update only if cache is expired (ie there is change in manifest file). So that doesn't help.
Anyone knows a programmatic way of expiring the application cache and forcing download?
AFAIK, the manifest
is the only means of initiating an update. The HTML5 Rocks web site has an article that talks about programmatically updating the cache (after a manifest
update) by immediately calling applicationCache.swapCache()
after listening for an UPDATEREADY
state in appCache.status
.
I'm not sure if that will suffice, but its a good read (scroll down to "Updating the Cache") -- http://www.html5rocks.com/tutorials/appcache/beginner/
It's true that an update is triggered only by an "updated" manifest file. But some browser (FF, chrome) do not check all files referenced by the manifest file. For example jpg's will not tested whether the server has newer one. It seems that the general caching policy of the browser influences the update process. To force the browser to check all or some of the files beeing in the cache manifest you have to tag this files with "Cache-Control: no-cache" in the HTTP header.
You can control the update operation by using cookies. If you have a serverside script which interprets the cookie commands you can force the browser to obsolete cache contents via javascript. For example if the client performs an cache.update() having a cookie "cache_clear" set, the server may answer with response code 404 which causes the browser to obsolete the application cache content.
链接地址: http://www.djcxy.com/p/49758.html上一篇: 使用Google凭据在我的应用中登录Android
下一篇: HTML5离线缓存程序化过期