开发者

Invalidating an HTML5 cache (manifest) completely?

开发者 https://www.devze.com 2023-03-24 08:20 出处:网络
I have an iPhone web-app, and I want to know how to force a cache refresh. My cache manifest is this: CACHE MANIFEST

I have an iPhone web-app, and I want to know how to force a cache refresh.

My cache manifest is this:

CACHE MANIFEST
index.html
file1.css
file1.js

index.html is the meat of the application, so I put that in the cache. At this point, I seem to be boned, as I can't figure out how to get iPhone to inva开发者_开发问答lidate the cache. Even going to Settings > Safari > Clear Cache doesn't work, although I'd like to be able to control this programatically. Removing index.html from the manifest and re-adding it seems to work, but I would have to know that all my clients had a clean hit of the updated manifest.

How do I cache index.html and still have it updated when it changes?


Off the top of my head, any change to the manifest will do the trick - and manifests can contain comments starting with #. Just add a random comment and it'll work.

It's a useful property, when I worked on an HTML5 application in a git repository I used to have the manifest automatically regenerated with a comment containing the HEAD hash after each commit so that the changes always propagate to the users.


There seems to be a bug in WebKit Browsers preventing them to reload the website on manifest changes, see this link

Have no clue for a workaround except when I call the index.html directly.

No chance for a iPad/iPhone-WebApp pinned to do the job...


Yes, you can use JavaScript to force Safari to reload cached resource files.

According to Apple, modifying the cache manifest file will cause Safari to reload any changed resource files. But those reloaded files won't be used by the browser until the user visits the site a second time. That delay can a pain, especially during development.

To force Safari to reload the cache contents immediately, Apple says you can use this JavaScript to manipulate the applicationCache object:

function updateSite(event) {
    window.applicationCache.swapCache();
}
window.applicationCache.addEventListener('updateready', updateSite, false);
0

精彩评论

暂无评论...
验证码 换一张
取 消