Created
May 7, 2018 17:50
-
-
Save eliihen/2910495b893d966222e2a2680203fba9 to your computer and use it in GitHub Desktop.
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
if (navigator.serviceWorker && navigator.serviceWorker.controller) { | |
// Add an event to the Service Worker's lifecycle state change event | |
navigator.serviceWorker.controller.onstatechange = event => { | |
// When the worker becomes redundant, that means a new worker is | |
// replacing it and the user is seeing stale content | |
if (event.target.state === 'redundant') { | |
// Replace this with some way to show a notification in your app | |
showMessage( | |
'A new version of the website is available. ' + | |
'Click here or refresh the page to get it.', | |
window.location.reload | |
); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment