Skip to content

Instantly share code, notes, and snippets.

@beebole

beebole/index(html)2.js

Last active Jul 25, 2017
Embed
What would you like to do?
Mobile Offline - Service Worker Initialization
//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