Created
September 30, 2020 03:37
-
-
Save oahehc/c07a2a7725cf641b9521d676955f4d74 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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