Last active
July 25, 2017 19:57
-
-
Save beebole/1285f8f32e0de8d21e5ec482629caf22 to your computer and use it in GitHub Desktop.
Mobile Offline - Service Worker Initialization
This file contains 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
//Listen for claiming of our ServiceWorker | |
navigator.serviceWorker.addEventListener('controllerchange', function() { | |
console.log( 'Service worker status changed: ', this.controller.state ); | |
// Listen for changes in the state of our ServiceWorker | |
navigator.serviceWorker.controller.addEventListener('statechange', function() { | |
// If the ServiceWorker becomes "activated", let the user know they can go offline! | |
if (this.state === 'activated') { | |
window.location.reload( true ); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment