Skip to content

Instantly share code, notes, and snippets.

@webmaxru
Created February 27, 2019 23:55
Show Gist options
  • Save webmaxru/3f91f2b453fdecd042ed5ea018499d9a to your computer and use it in GitHub Desktop.
Save webmaxru/3f91f2b453fdecd042ed5ea018499d9a to your computer and use it in GitHub Desktop.
Workbox 4: workbox-window. Service worker with update
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