Created
July 3, 2018 02:21
-
-
Save baorv/d3079294187a76f7e5ea38ec5f8461b2 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
| export default function register() { | |
| if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { | |
| window.addEventListener('load', () => { | |
| const swUrl = 'service-worker.js'; | |
| navigator.serviceWorker | |
| .register(swUrl) | |
| .then(registration => { | |
| registration.onupdatefound = () => { | |
| const installingWorker = registration.installing; | |
| installingWorker.onstatechange = () => { | |
| if (installingWorker.state === 'installed') { | |
| if (navigator.serviceWorker.controller) { | |
| console.log('New content is available; please refresh.'); | |
| } else { | |
| console.log('Content is cached for offline use.'); | |
| } | |
| } | |
| }; | |
| }; | |
| }) | |
| .catch(error => { | |
| console.error('Error during service worker registration:', error); | |
| }); | |
| }); | |
| } | |
| } | |
| export function unregister() { | |
| if ('serviceWorker' in navigator) { | |
| navigator.serviceWorker.ready.then(registration => { | |
| registration.unregister(); | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment