Skip to content

Instantly share code, notes, and snippets.

@oahehc
Created September 30, 2020 03:37
Show Gist options
  • Save oahehc/c07a2a7725cf641b9521d676955f4d74 to your computer and use it in GitHub Desktop.
Save oahehc/c07a2a7725cf641b9521d676955f4d74 to your computer and use it in GitHub Desktop.
navigator.serviceWorker
.register("/sw.js")
.then((reg) => {
// no controller exist, page wasn't loaded via a service worker
if (!navigator.serviceWorker.controller) {
return;
}
if (reg.waiting) {
// If we have a new version of the service worker is waiting,
// we can display the message to the user and allow them
// to trigger updates manually.
// Otherwise, the browser will replace the service worker
// when the user closes or navigate away from all tabs using
// the current service worker.
return;
}
if (reg.installing) {
// If we have a new service worker is installing, we can
// tracking the status and display the message once the
// installation is finished.
return;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment