Skip to content

Instantly share code, notes, and snippets.

@eliihen
Created May 7, 2018 17:50
Show Gist options
  • Save eliihen/2910495b893d966222e2a2680203fba9 to your computer and use it in GitHub Desktop.
Save eliihen/2910495b893d966222e2a2680203fba9 to your computer and use it in GitHub Desktop.
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