Skip to content

Instantly share code, notes, and snippets.

@beebole
Last active July 25, 2017 19:57
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 beebole/1285f8f32e0de8d21e5ec482629caf22 to your computer and use it in GitHub Desktop.
Save beebole/1285f8f32e0de8d21e5ec482629caf22 to your computer and use it in GitHub Desktop.
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