Created
February 27, 2019 23:55
-
-
Save webmaxru/3f91f2b453fdecd042ed5ea018499d9a to your computer and use it in GitHub Desktop.
Workbox 4: workbox-window. Service worker with update
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
import { Workbox } from 'workbox-window'; | |
if ('serviceWorker' in navigator) { | |
const wb = new Workbox('service-worker.js'); | |
wb.addEventListener('installed', event => { | |
if (event.isUpdate) { | |
if (confirm(`New content is available!. Click OK to refresh`)) { | |
window.location.reload(); | |
} | |
} | |
}); | |
wb.register(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment