Created
October 18, 2013 15:59
-
-
Save ghoullier/7043717 to your computer and use it in GitHub Desktop.
Iframe manifest proxy, avoid main page caching
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
<!DOCTYPE html> | |
<html manifest="manifest.appcache"> | |
<body> | |
<script> | |
(function (root) { | |
// Local variables | |
var parent = root.parent, | |
location = root.location; | |
// Add event when root is loaded | |
root.addEventListener('load', function onRootLoad() { | |
var appCache = root.applicationCache; | |
if (appCache) { | |
appCache.addEventListener('cached', function onCached() { | |
detachIframe(); | |
}); | |
appCache.addEventListener('noupdate', function onNoUpdate() { | |
detachIframe(); | |
}); | |
appCache.addEventListener('updateready', function onUpdateReady() { | |
location.reload(); | |
}); | |
} else { | |
// ApplicationCache is not supported | |
} | |
}); | |
/** | |
* Detach iframe from parent context | |
* @return {void} | |
*/ | |
function detachIframe() { | |
if (parent && parent !== root) { | |
var parentDoc = parent.document, | |
proxy = parentDoc.querySelector('[data-manifest-proxy]'); | |
if (proxy) { | |
proxy.parentNode.removeChild(proxy); | |
} else { | |
// Unable to find #manifest-proxy element | |
} | |
} else { | |
// Iframe parent context is not defined | |
} | |
} | |
}(this)); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment