HTML5 App Cache: Manifest ist updated but files are taken from appcache one more time

こ雲淡風輕ζ 提交于 2019-12-09 17:05:20

问题


I have a cache manifest with a comment in it

# Version 3.2

in order to update all the App I simply change the Version number. It works, but:

When I update the manifest, everything is updated correctly (new cache is filled) but the actual files are taken ONE more time from the (old) cache. when I reload twice everything is updated. Is this behaviour correct? Using chrome 21.

Thanks


回答1:


Yes, this is the current "correct" behaviour. This is what happens:

When you just made changes to the manifest file, and you refresh the browser, this is what happens (assuming you're online)

  • the browser first loads back all the files in the cache
  • then the browser check online for your manifest file
  • it detects that the manifest file has changed, it will then proceed to download the new files
  • however, keep in mind, at this time, you will still be looking at your 'old files' because the browser has loaded the old files before going online to download the 'new files'
  • if at this point, if you hit refresh again (2nd time), you should get the 'new files'

This is currently the standard behaviour. Some people put some event handlers to prompt the user to do another refresh (after the 1st refresh)

Personally, I think the browser should be responsible to alert the user to make another refresh after finish downloading the new files, but right now, most people put in event handlers from the "window.applicationCache" to fire events to help manage this.

To look at an example of using window.applicationCache, go here : http://www.html5rocks.com/en/tutorials/appcache/beginner/

it's under the "Updating the Cache" section.




回答2:


It is possible to instantly swap the cache as described here:

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


来源:https://stackoverflow.com/questions/12504834/html5-app-cache-manifest-ist-updated-but-files-are-taken-from-appcache-one-more

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!