Skip to content

Instantly share code, notes, and snippets.

@johanbove
Last active July 4, 2018 06:14
Show Gist options
  • Save johanbove/9570df0ee85bbb3a630a to your computer and use it in GitHub Desktop.
Save johanbove/9570df0ee85bbb3a630a to your computer and use it in GitHub Desktop.
Cutting the mustard
// From Christian Heillman
// http://www.slideshare.net/cheilmann/jsday-48092671
// http://justmarkup.com/log/2015/02/26/cut-the-mustard-revisited/
if ('querySelector' in document &&
'localStorage' in window &&
'addEventListener' in window) {
// Modern browser. Let's add JavaScript functionality
}
// Jake Archibald
// A nice way to prevent your JS running in IE<10 and Android Webkit
// http://caniuse.com/#feat=pagevisibility
if (!('visibilityState' in document)) {
return;
}
// extending the baseline
// Christian Heilmann
if ('visibilityState' in document) {
// Modern browser. Let's load JavaScript
if ('serviceWorker' in navigator) {
// Let's add offline support
navigator.serviceworker.register('sw.js', {
scope: './'
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment