Piped/src/registerServiceWorker.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-11-15 11:27:44 +00:00
/* eslint-disable no-console */
import { register } from 'register-service-worker'
if (process.env.NODE_ENV === 'production') {
2020-11-16 10:36:37 +00:00
register(`${process.env.BASE_URL}service-worker.js`, {
ready() {
console.log(
'App is being served from cache by a service worker.\n' +
'For more details, visit https://goo.gl/AFskqB'
)
},
registered() {
console.log('Service worker has been registered.')
},
cached() {
console.log('Content has been cached for offline use.')
},
updatefound() {
console.log('New content is downloading.')
},
updated() {
console.log('New content is available; please refresh.')
2020-11-17 05:15:35 +00:00
caches.keys().then(function (names) {
2020-11-16 10:36:37 +00:00
for (let name of names) caches.delete(name);
2020-11-16 10:41:47 +00:00
})
2020-11-16 10:36:37 +00:00
},
offline() {
console.log('No internet connection found. App is running in offline mode.')
},
error(error) {
console.error('Error during service worker registration:', error)
}
})
2020-11-15 11:27:44 +00:00
}