Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 415
LukeSolar Avatar asked Sep 20 '12 00:09

LukeSolar


2 Answers

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.

like image 93
Harvey Darvey Avatar answered Oct 18 '22 10:10

Harvey Darvey


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

function updateSite(event) {
    window.applicationCache.swapCache();
}
window.applicationCache.addEventListener('updateready', updateSite, false);
like image 23
Aides Avatar answered Oct 18 '22 11:10

Aides