Last active
September 19, 2019 14:12
-
-
Save wilsonpage/7262cf36d155df1aa23bd304d8aaf467 to your computer and use it in GitHub Desktop.
Detect if a core script failed to load
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
<html> | |
<head> | |
… | |
</head> | |
<body> | |
… | |
<script type="text/javascript"> | |
window.addEventListener('error', function(error) { | |
if (error.target instanceof HTMLScriptElement) { | |
const script = error.target; | |
const isLocalScript = script.src.indexOf(location.host) > -1; | |
if (!isLocalScript) return; | |
const shouldReload = confirm('a script failed to load properly, try to reload?'); | |
if (shouldReload) location.reload(true); | |
} | |
}, true); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment