Created
June 15, 2011 09:07
-
-
Save Takazudo/1026759 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* cache manifest debug from http://jonathanstark.com/blog/2009/09/27/debugging-html-5-offline-application-cache/ */ | |
(function(){ | |
var $log = $('#log'); // #log is ul | |
function log(msg){ | |
$log.append('<li>' + msg + '</li>'); | |
} | |
var cacheStatusValues = []; | |
cacheStatusValues[0] = 'uncached'; | |
cacheStatusValues[1] = 'idle'; | |
cacheStatusValues[2] = 'checking'; | |
cacheStatusValues[3] = 'downloading'; | |
cacheStatusValues[4] = 'updateready'; | |
cacheStatusValues[5] = 'obsolete'; | |
var cache = window.applicationCache; | |
cache.addEventListener('cached', logEvent, false); | |
cache.addEventListener('checking', logEvent, false); | |
cache.addEventListener('downloading', logEvent, false); | |
cache.addEventListener('error', logEvent, false); | |
cache.addEventListener('noupdate', logEvent, false); | |
cache.addEventListener('obsolete', logEvent, false); | |
cache.addEventListener('progress', logEvent, false); | |
cache.addEventListener('updateready', logEvent, false); | |
function logEvent(e) { | |
var online, status, type, message; | |
online = (navigator.onLine) ? 'yes' : 'no'; | |
status = cacheStatusValues[cache.status]; | |
type = e.type; | |
message = 'online: ' + online; | |
message+= ', event: ' + type; | |
message+= ', status: ' + status; | |
if (type == 'error' && navigator.onLine) { | |
message+= ' (prolly a syntax error in manifest)'; | |
} | |
log(message); | |
} | |
window.applicationCache.addEventListener( | |
'updateready', | |
function(){ | |
window.applicationCache.swapCache(); | |
log('swap cache has been called'); | |
}, | |
false | |
); | |
setInterval(function(){cache.update()}, 10000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment