Primo Committ
This commit is contained in:
24
src-pwa/custom-service-worker.js
Normal file
24
src-pwa/custom-service-worker.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* This file (which will be your service worker)
|
||||
* is picked up by the build system ONLY if
|
||||
* quasar.conf > pwa > workboxPluginMode is set to "InjectManifest"
|
||||
*/
|
||||
|
||||
self.addEventListener('install', function(event) {
|
||||
console.log('[Service Worker] Installing Service Worker ...', event);
|
||||
});
|
||||
|
||||
self.addEventListener('activate', function(event) {
|
||||
console.log('[Service Worker] Activating Service Worker ...', event);
|
||||
return self.clients.claim();
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', function(event) {
|
||||
//console.log('[Service Worker] Fetching something ....', event);
|
||||
if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') {
|
||||
console.log('SAME ORIGIN!', event);
|
||||
return;
|
||||
}
|
||||
event.respondWith(fetch(event.request));
|
||||
});
|
||||
|
||||
35
src-pwa/register-service-worker.js
Normal file
35
src-pwa/register-service-worker.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is picked up by the build system only
|
||||
* when building for PRODUCTION
|
||||
*/
|
||||
|
||||
import {register} from 'register-service-worker'
|
||||
|
||||
register(process.env.SERVICE_WORKER_FILE, {
|
||||
ready() {
|
||||
console.log('READY::: App is being served from cache by a service worker.')
|
||||
},
|
||||
registered(registration) { // registration -> a ServiceWorkerRegistration instance
|
||||
console.log('REGISTERED::: !!!')
|
||||
},
|
||||
cached(registration) { // registration -> a ServiceWorkerRegistration instance
|
||||
console.log('CACHED::: Content has been cached for offline use.')
|
||||
},
|
||||
updatefound(registration) { // registration -> a ServiceWorkerRegistration instance
|
||||
console.log('UPDATEFOUND::: New content is downloading.')
|
||||
},
|
||||
updated(registration) { // registration -> a ServiceWorkerRegistration instance
|
||||
console.log('New content is available; please refresh.')
|
||||
},
|
||||
offline() {
|
||||
console.log('No internet connection found. App is running in offline mode.')
|
||||
},
|
||||
error(err) {
|
||||
console.error('Error during service worker registration:', err)
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
// ServiceWorkerRegistration: https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
|
||||
|
||||
|
||||
Reference in New Issue
Block a user