Last Updated: February 25, 2016
·
2.268K
· milesmatthias

Periodically Check AppCache update

By default, Google Chrome will only check to see if there is a change in your appcache manifest when the user loads (/refreshes) the page. Well, what if your user never refreshes the page? They'll never get the latest code. To solve this, you can periodically check to see if the the appcache has changed. Notice the error handling to prevent extra checks and any DOM errors.

// Set up an automatic appcache updater
setInterval(function(){
    if(navigator.onLine){
        // console.log('Online, so I should check if the appcache has changed.')
        // If we don't make sure there is an appcache to do stuff with, we'll get a DOM EXCEPTION: ERROR CODE 11
        if(window.applicationCache.status != window.applicationCache.UNCACHED)
            window.applicationCache.update();
     }/*else{
         console.log('Offline, so no checking.')
     }*/
}, 7200000); // 2 hours