trying to fix service worker
This commit is contained in:
parent
98d64800fc
commit
6a23a1212a
@ -1,5 +1,6 @@
|
|||||||
FROM node:lts-alpine as builder
|
FROM node:lts-alpine as builder
|
||||||
COPY ./frontend .
|
COPY ./frontend .
|
||||||
|
ENV NODE_ENV=production
|
||||||
RUN npm install
|
RUN npm install
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
FROM python:3.7-slim-stretch
|
FROM python:3.7-slim-stretch
|
||||||
|
@ -2,12 +2,6 @@
|
|||||||
|
|
||||||
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 () {
|
||||||
@ -26,8 +20,9 @@ if (process.env.NODE_ENV === 'production') {
|
|||||||
console.log('New content is downloading.')
|
console.log('New content is downloading.')
|
||||||
},
|
},
|
||||||
updated (registration) {
|
updated (registration) {
|
||||||
console.log('New content is available; please refresh.')
|
console.log('New content is available; please refresh.')
|
||||||
notifyAboutUpdate(registration.waiting)
|
let confirmationResult = confirm("New content found! Do you want to reload the app?")
|
||||||
|
if (confirmationResult) registration.waiting.postMessage({action: "skipWaiting"})
|
||||||
},
|
},
|
||||||
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.')
|
||||||
@ -35,12 +30,12 @@ if (process.env.NODE_ENV === 'production') {
|
|||||||
error (error) {
|
error (error) {
|
||||||
console.error('Error during service worker registration:', error)
|
console.error('Error during service worker registration:', error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
var refreshing;
|
let refreshing
|
||||||
navigator.serviceWorker.addEventListener("controllerchange", function () {
|
navigator.serviceWorker.addEventListener("controllerchange", e=>{
|
||||||
if (refreshing) return;
|
if (refreshing) return
|
||||||
window.location.reload();
|
window.location.reload()
|
||||||
refreshing = true;
|
refreshing = true
|
||||||
})
|
})
|
||||||
}
|
}
|
@ -1,9 +1,9 @@
|
|||||||
self.__precacheManifest = [].concat(self.__precacheManifest || []);
|
self.__precacheManifest = [].concat(self.__precacheManifest || []);
|
||||||
workbox.precaching.suppressWarnings()
|
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
|
||||||
workbox.precaching.precacheAndRoute(self.__precacheManifest, {})
|
|
||||||
|
|
||||||
self.addEventListener('message', msg => {
|
// install new service worker when ok, then reload page.
|
||||||
if (msg.data.action == 'skipwaiting') {
|
self.addEventListener("message", msg=>{
|
||||||
self.skipWaiting();
|
if (msg.data.action=='skipWaiting'){
|
||||||
}
|
self.skipWaiting()
|
||||||
|
}
|
||||||
})
|
})
|
Loading…
Reference in New Issue
Block a user