0

I'm using the application cache for an offline mode for my application, and the main page will be changed often, so I want to update the cache every time the HTML page is updated.

Or, to update the cache for every page's load.

I'm using this code, but it doesn't work:

window.addEventListener('load', function(e) {

  window.applicationCache.addEventListener('updateready', function(e) {
    if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
      // Browser downloaded a new app cache.
      if (confirm('A new version of this site is available. Load it?')) {
        window.location.reload();
      }
    } else {
      // Manifest didn't changed. Nothing new to server.
    }
  }, false);

}, false);
AstroCB
  • 12,337
  • 20
  • 57
  • 73
Stranger B.
  • 9,004
  • 21
  • 71
  • 108

1 Answers1

0

...So I want to update the cache everytime the html page is updated

You will have to manually update the cache-manifest file (by appending a # to the end of it, or making some other insignificant change. If you want to automate it, write some kind of script that will watch your project directory and add a # to the cache manifest anytime there is a change.

Or, to update the cache for every page's load.

You will need to configure your web server to disable caching of the manifest, so it will always server it up to the browser instead of instructing the browser to use the cached version.

This is an excellent resource.

Mike Nitchie
  • 1,166
  • 2
  • 13
  • 29