try adding update button again
This commit is contained in:
parent
b7096d8646
commit
98d64800fc
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
import { register } from 'register-service-worker'
|
import { register } from 'register-service-worker'
|
||||||
|
|
||||||
|
const notifyAboutUpdate = worker => {
|
||||||
|
if (confirm('New version available, update?')) {
|
||||||
|
worker.postMessage({ action : "skipWaiting"})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
register(`${process.env.BASE_URL}service-worker.js`, {
|
register(`${process.env.BASE_URL}service-worker.js`, {
|
||||||
ready () {
|
ready () {
|
||||||
@ -19,8 +25,9 @@ if (process.env.NODE_ENV === 'production') {
|
|||||||
updatefound () {
|
updatefound () {
|
||||||
console.log('New content is downloading.')
|
console.log('New content is downloading.')
|
||||||
},
|
},
|
||||||
updated () {
|
updated (registration) {
|
||||||
console.log('New content is available; please refresh.')
|
console.log('New content is available; please refresh.')
|
||||||
|
notifyAboutUpdate(registration.waiting)
|
||||||
},
|
},
|
||||||
offline () {
|
offline () {
|
||||||
console.log('No internet connection found. App is running in offline mode.')
|
console.log('No internet connection found. App is running in offline mode.')
|
||||||
@ -29,4 +36,11 @@ if (process.env.NODE_ENV === 'production') {
|
|||||||
console.error('Error during service worker registration:', error)
|
console.error('Error during service worker registration:', error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var refreshing;
|
||||||
|
navigator.serviceWorker.addEventListener("controllerchange", function () {
|
||||||
|
if (refreshing) return;
|
||||||
|
window.location.reload();
|
||||||
|
refreshing = true;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
9
frontend/src/service-worker.js
Normal file
9
frontend/src/service-worker.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
self.__precacheManifest = [].concat(self.__precacheManifest || []);
|
||||||
|
workbox.precaching.suppressWarnings()
|
||||||
|
workbox.precaching.precacheAndRoute(self.__precacheManifest, {})
|
||||||
|
|
||||||
|
self.addEventListener('message', msg => {
|
||||||
|
if (msg.data.action == 'skipwaiting') {
|
||||||
|
self.skipWaiting();
|
||||||
|
}
|
||||||
|
})
|
@ -1,5 +1,3 @@
|
|||||||
const { GenerateSW } = require("workbox-webpack-plugin");
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
publicPath: "./",
|
publicPath: "./",
|
||||||
pwa: {
|
pwa: {
|
||||||
@ -10,16 +8,10 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
workboxPluginMode: 'InjectManifest',
|
workboxPluginMode: 'InjectManifest',
|
||||||
workboxOptions: {
|
workboxOptions: {
|
||||||
swSrc: 'src/registerServiceWorker.js'
|
swSrc: 'src/service-worker.js'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
configureWebpack: {
|
configureWebpack: {
|
||||||
plugins: [new GenerateSW({
|
|
||||||
clientsClaim: true,
|
|
||||||
skipWaiting: true,
|
|
||||||
cleanupOutdatedCaches: true,
|
|
||||||
navigateFallback: 'index.html',
|
|
||||||
})],
|
|
||||||
output: {
|
output: {
|
||||||
crossOriginLoading: 'anonymous'
|
crossOriginLoading: 'anonymous'
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user