Created
December 9, 2014 13:59
-
-
Save Mehuge/c04fa544e8b8f3056a16 to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://xhr-progressive-timeouts.googlecode.com/hg/trunk/lib/xhr-pt.js"></script> | |
<style type="text/css"> | |
#debug .info { color: silver; } | |
#debug .ok { color: green; } | |
#debug .error { color: red; } | |
</style> | |
</head> | |
<body> | |
<div id="debug"></div> | |
<script> | |
var DBG = document.getElementById("debug"); | |
function LOG(cls, s) { | |
var div = document.createElement("div"); | |
div.innerText = s; | |
div.className = cls; | |
DBG.appendChild(div); | |
} | |
LOG("info", "Loading cache.manifest"); | |
XHR("cache.manifest").done(function(response) { | |
LOG("info", "cache.manifest Loaded OK"); | |
var lines = response.getXhr().responseText.split("\n"), l, section = 0; | |
LOG("info", "parsing cache.manifest"); | |
while (l = lines.shift()) { | |
if (l[0] == '#') continue; // ignore comment | |
switch(l) { | |
case "CACHE MANIFEST": | |
LOG("info", "GOT CACHE MANIFEST"); | |
section = 1; | |
break; | |
case "CACHE:": section = 1; LOG("info", l); break; | |
case "FALLBACK:": section = 3; LOG("info", l); break; | |
case "NETWORK:": section = 2; LOG("info", l); break; | |
default: | |
if (section === 0) { | |
console.error('Missing CACHE MANIFEST header'); | |
} else if (section === 1) { | |
(function(url) { | |
XHR(url).on("error", function(e) { | |
LOG("error", url + ' error ' + e.message); | |
}).done(function(response) { | |
LOG("ok", url + ' status ' + response.status); | |
}); | |
})(l); | |
} else if (section === 2) { | |
// ignore these for now | |
LOG("info", "ignore NETWORK " + l); | |
} else if (section === 3) { | |
// ignore these for now | |
LOG("info", "ignore FALLBACK " + l); | |
} | |
break; | |
} | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment