Skip to content

Instantly share code, notes, and snippets.

@Mehuge
Created December 9, 2014 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mehuge/c04fa544e8b8f3056a16 to your computer and use it in GitHub Desktop.
Save Mehuge/c04fa544e8b8f3056a16 to your computer and use it in GitHub Desktop.
<!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