Aggiornamento con l'update di ncu -u (dei pacchetti yarn)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable import/namespace */
|
||||
import { cleanupOutdatedCaches, precacheAndRoute } from 'workbox-precaching';
|
||||
import { registerRoute } from 'workbox-routing';
|
||||
import { clientsClaim, setCacheNameDetails, skipWaiting } from 'workbox-core';
|
||||
@@ -14,16 +15,34 @@ import { ExpirationPlugin } from 'workbox-expiration';
|
||||
|
||||
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
||||
|
||||
importScripts('https://storage.googleapis.com/workbox-cdn/releases/6.5.4/workbox-sw.js');
|
||||
|
||||
self.addEventListener('install', () => self.skipWaiting());
|
||||
self.addEventListener('activate', (event) => event.waitUntil(self.clients.claim()));
|
||||
self.addEventListener('activate', (event) => {
|
||||
// console.log('CLAIM');
|
||||
//event.waitUntil(self.clients.claim())
|
||||
|
||||
event.waitUntil(async () => {
|
||||
// Check for a new service worker version
|
||||
const registration = await navigator.serviceWorker.getRegistration();
|
||||
if (registration && registration.waiting) {
|
||||
// A new service worker is waiting, trigger a page reload
|
||||
await registration.waiting.postMessage({ type: 'SKIP_WAITING' });
|
||||
self.skipWaiting();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
const VersioneApp = '1.0.46';
|
||||
|
||||
console.log(' [ VER-' + VersioneApp + ' ] _---------________------ PAO: this is my custom service worker');
|
||||
|
||||
importScripts('js/idb.js', 'js/storage.js', 'js/workbox-sw.js');
|
||||
importScripts('js/idb.js', 'js/storage.js');
|
||||
|
||||
let port = self.location.hostname.startsWith('test') ? 3001 : 3000;
|
||||
console.log('SW- app ver ' + VersioneApp + ' on port ' + port);
|
||||
|
||||
|
||||
// Function helpers
|
||||
async function writeData(table, data) {
|
||||
@@ -147,8 +166,8 @@ if (workbox) {
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', function (event) {
|
||||
console.log('[Service Worker] Fetching something ....', event);
|
||||
console.log('event.request.cache=', event.request.cache)
|
||||
// console.log('[Service Worker] Fetching something ....', event);
|
||||
// console.log('event.request.cache=', event.request.cache)
|
||||
if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') {
|
||||
console.log('SAME ORIGIN!', event);
|
||||
return;
|
||||
@@ -158,28 +177,29 @@ if (workbox) {
|
||||
if (cachedResponse) {
|
||||
return cachedResponse;
|
||||
}
|
||||
|
||||
|
||||
console.log('*** REQUEST', event.request);
|
||||
try {
|
||||
const response = await fetch(event.request);
|
||||
|
||||
|
||||
if (!response || response.status !== 200 || response.type !== 'basic') {
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
if (ENABLE_DYNAMIC_CACHING) {
|
||||
const responseToCache = response.clone();
|
||||
const cache = await caches.open(DYNAMIC_CACHE)
|
||||
await cache.put(event.request, response.clone());
|
||||
await cache.put(event.request, responseToCache);
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
} catch (e) {
|
||||
return '';
|
||||
console.error('[Service Worker] fetch error', e);
|
||||
return new Response('fetch error', { status: 500 });
|
||||
}
|
||||
})());
|
||||
});
|
||||
|
||||
|
||||
self.addEventListener('sync', event => {
|
||||
console.log('[Service Worker V5] Background syncing', event);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user