Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

ApplicationCache Updater

By: a guest on Jun 25th, 2010  |  syntax: JavaScript  |  size: 0.78 KB  |  views: 623  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data