Advertisement
Guest User

ApplicationCache Updater

a guest
Jun 25th, 2010
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // allows user to update app at runtime when cache-manifest is changed on server
  2. console.log("App cache status: " + getCacheStatus(window.applicationCache.status));
  3. var updateCacheHandler = function() {
  4.     if( confirm("Update available, update now?") ) {
  5.         window.applicationCache.update();
  6.         window.applicationCache.swapCache();
  7.         window.location.reload(true);
  8.     }
  9.     window.applicationCache.removeEventListener('updateready', updateCacheHandler);
  10. }
  11. window.applicationCache.addEventListener('updateready', updateCacheHandler, false);
  12.  
  13.  
  14. function getCacheStatus(status) {
  15.     switch(status.toString()) {
  16.         case "0" : return "UNCACHED";
  17.         case "1" : return "IDLE";
  18.         case "2" : return "CHECKING";
  19.         case "3" : return "DOWNLOADING";
  20.         case "4" : return "UPDATEREADY";
  21.     }
  22.     return null;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement