Skip to content

Instantly share code, notes, and snippets.

@tracker1
Created March 28, 2020 18:06
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 tracker1/8eea53ec700a0fea725123516a30a70a to your computer and use it in GitHub Desktop.
Save tracker1/8eea53ec700a0fea725123516a30a70a to your computer and use it in GitHub Desktop.
Modern browser SPA precheck.js
// precheck
try {
eval('(function() { async _ => _; })();');
if (typeof fetch !== 'function') throw new Error('No fetch api');
} catch (e) {
// render unsupported message in half a second - after error trap
window.setTimeout(function() {
// fallback render for development
var body = document.getElementsByTagName('body')[0];
body.className = 'message';
body.innerHTML =
'\
<h1>Unsupported Browser</h1> \
<p>For security reasons, only current/green browsers are supported.</p> \
<p>Current versions of Chrome, Firefox, Safari and Edge should work</p> \
<p>For more information see <a href="https://browsehappy.com/">browsehappy.com</a></p> \
';
}, 500);
// remove all scripts
var r = document.getElementsByTagName('script');
for (var i = r.length - 1; i >= 0; i--) {
r[i].parentNode.removeChild(r[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment