diff --git a/registerServiceWorker.js b/registerServiceWorker.js index fa7438a..9b84956 100644 --- a/registerServiceWorker.js +++ b/registerServiceWorker.js @@ -1,8 +1,11 @@ +let refresh = false + function invokeServiceWorkerUpdateFlow (registration) { const agree = confirm('New version of the app is available. Refresh now?') if (agree) { if (registration.waiting) { // let waiting Service Worker know it should became active + refresh = true registration.waiting.postMessage({ type: 'SKIP_WAITING' }) } } @@ -23,19 +26,18 @@ if ('serviceWorker' in navigator) { if (newRegestration) { // wait until the new Service worker is actually installed (ready to take over) newRegestration.addEventListener('statechange', () => { - if (registration.waiting) { + if (registration.waiting && navigator.serviceWorker.controller) { invokeServiceWorkerUpdateFlow(registration) } }) } }) - let refreshing = false // detect controller change and refresh the page navigator.serviceWorker.addEventListener('controllerchange', () => { - if (!refreshing) { + if (refresh) { window.location.reload() - refreshing = true + refresh = false } }) }) diff --git a/src/main.js b/src/main.js index deca75d..0426b3d 100644 --- a/src/main.js +++ b/src/main.js @@ -12,7 +12,9 @@ import '@/assets/styles/dialogs.css' import '@/assets/styles/tooltips.css' import '@/assets/styles/messages.css' -import '../registerServiceWorker' +if (!['localhost', '127.0.0.1'].includes(location.hostname)) { + import('../registerServiceWorker') // eslint-disable-line no-unused-expressions +} Vue.use(VuePlugin) Vue.use(VModal) diff --git a/vue.config.js b/vue.config.js index a050aca..23c6577 100644 --- a/vue.config.js +++ b/vue.config.js @@ -12,6 +12,7 @@ module.exports = { { from: 'LICENSE', to: './' } ]), new WorkboxPlugin.GenerateSW({ + exclude: [/\.map$/, 'LICENSE', 'queries.json'], clientsClaim: true, skipWaiting: false, maximumFileSizeToCacheInBytes: 40000000