- check updates
- risolto problema della generazione dei PDF, avevo modificato in CMyPageElem , se si cambia qualcosa occorre stare attenti a mettere !hideHeader
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
/* global workbox */
|
||||
/* global cfgenv */
|
||||
|
||||
const VITE_APP_VERSION = '1.2.72';
|
||||
const VITE_APP_VERSION = '1.2.75';
|
||||
|
||||
// Costanti di configurazione
|
||||
const DYNAMIC_CACHE = 'dynamic-cache-v2';
|
||||
@@ -38,10 +38,19 @@ const CACHE_NAME = 'pwa-cache-' + VITE_APP_VERSION; // Nome della cache
|
||||
importScripts('workbox/workbox-sw.js');
|
||||
|
||||
import { clientsClaim } from 'workbox-core';
|
||||
import { precacheAndRoute, cleanupOutdatedCaches, createHandlerBoundToURL } from 'workbox-precaching';
|
||||
import {
|
||||
precacheAndRoute,
|
||||
cleanupOutdatedCaches,
|
||||
createHandlerBoundToURL,
|
||||
} from 'workbox-precaching';
|
||||
import { registerRoute, NavigationRoute } from 'workbox-routing';
|
||||
import { setCacheNameDetails } from 'workbox-core';
|
||||
import { NetworkOnly, NetworkFirst, StaleWhileRevalidate, CacheFirst } from 'workbox-strategies';
|
||||
import {
|
||||
NetworkOnly,
|
||||
NetworkFirst,
|
||||
StaleWhileRevalidate,
|
||||
CacheFirst,
|
||||
} from 'workbox-strategies';
|
||||
|
||||
import { CacheableResponsePlugin } from 'workbox-cacheable-response';
|
||||
import { ExpirationPlugin } from 'workbox-expiration';
|
||||
@@ -66,12 +75,15 @@ setCacheNameDetails({
|
||||
runtime: 'runtime',
|
||||
});
|
||||
|
||||
// ✅ SOLUZIONE: Sii più specifico
|
||||
const precacheList = (self.__WB_MANIFEST || []).filter((entry) => {
|
||||
// Esclude tutto ciò che si trova nella cartella 'upload'
|
||||
if (entry.url.includes('/upload/')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
const url = entry.url;
|
||||
// Escludi file grandi, upload, e risorse dinamiche
|
||||
return (
|
||||
!url.includes('/upload/') &&
|
||||
!url.includes('/assets/videos/') &&
|
||||
!url.match(/\.(mp4|webm|zip|pdf)$/)
|
||||
);
|
||||
});
|
||||
|
||||
// Precache solo i file filtrati
|
||||
@@ -85,6 +97,12 @@ self.addEventListener('install', () => {
|
||||
self.skipWaiting();
|
||||
|
||||
clientsClaim();
|
||||
// Notifica il frontend che c'è un nuovo SW pronto
|
||||
self.clients.matchAll().then((clients) => {
|
||||
clients.forEach((client) => {
|
||||
client.postMessage({ type: 'SW_UPDATED' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Attivazione del Service Worker
|
||||
@@ -93,13 +111,19 @@ self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((cacheNames) => {
|
||||
return Promise.all(
|
||||
cacheNames.filter((name) => name !== CACHE_NAME && name !== DYNAMIC_CACHE).map((name) => caches.delete(name))
|
||||
cacheNames
|
||||
.filter((name) => name !== CACHE_NAME && name !== DYNAMIC_CACHE)
|
||||
.map((name) => caches.delete(name))
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
console.log(' [ VER-' + VITE_APP_VERSION + ' ] _---------________------ PAO: this is my custom service worker: ');
|
||||
console.log(
|
||||
' [ VER-' +
|
||||
VITE_APP_VERSION +
|
||||
' ] _---------________------ PAO: this is my custom service worker: '
|
||||
);
|
||||
|
||||
try {
|
||||
importScripts('/js/idb.js', '/js/storage.js');
|
||||
@@ -170,7 +194,10 @@ if (workbox) {
|
||||
/^https:\/\/fonts\.(?:googleapis|gstatic)\.com/,
|
||||
new StaleWhileRevalidate({
|
||||
cacheName: `${CACHE_PREFIX}-google-fonts-${CACHE_VERSION}`,
|
||||
plugins: [new CacheableResponsePlugin({ statuses: [0, 200] }), new ExpirationPlugin({ maxEntries: 30 })],
|
||||
plugins: [
|
||||
new CacheableResponsePlugin({ statuses: [0, 200] }),
|
||||
new ExpirationPlugin({ maxEntries: 30 }),
|
||||
],
|
||||
})
|
||||
);
|
||||
|
||||
@@ -179,7 +206,7 @@ if (workbox) {
|
||||
({ request }) => request.destination === 'document',
|
||||
new NetworkFirst({
|
||||
cacheName: `${CACHE_PREFIX}-html-cache-${CACHE_VERSION}`,
|
||||
networkTimeoutSeconds: 5, // timeout rapido
|
||||
networkTimeoutSeconds: 10, // timeout rapido
|
||||
plugins: [
|
||||
new CacheableResponsePlugin({ statuses: [0, 200] }),
|
||||
new ExpirationPlugin({ maxEntries: 20, maxAgeSeconds: 24 * 60 * 60 }), // 1 giorno
|
||||
@@ -192,7 +219,7 @@ if (workbox) {
|
||||
({ url }) => url.hostname === API_DOMAIN,
|
||||
new NetworkFirst({
|
||||
cacheName: `${CACHE_PREFIX}-api-cache-${CACHE_VERSION}`,
|
||||
networkTimeoutSeconds: 5,
|
||||
networkTimeoutSeconds: 10,
|
||||
fetchOptions: { credentials: 'include' },
|
||||
plugins: [
|
||||
new CacheableResponsePlugin({ statuses: [0, 200] }),
|
||||
@@ -211,8 +238,15 @@ if (workbox) {
|
||||
|
||||
const syncStore = {};
|
||||
self.addEventListener('message', (event) => {
|
||||
if (event.data && (event.data.type === 'SKIP_WAITING' || event.data.action === 'skipWaiting')) {
|
||||
if (
|
||||
event.data &&
|
||||
(event.data.type === 'SKIP_WAITING' || event.data.action === 'skipWaiting')
|
||||
) {
|
||||
self.skipWaiting();
|
||||
// Opzionale: rispondi al client
|
||||
if (event.ports && event.ports[0]) {
|
||||
event.ports[0].postMessage({ success: true });
|
||||
}
|
||||
}
|
||||
if (event.data.type === 'sync') {
|
||||
console.log('addEventListener - message');
|
||||
@@ -445,7 +479,9 @@ if (workbox) {
|
||||
|
||||
self.addEventListener('push', (event) => {
|
||||
console.log('Push Notification received', event);
|
||||
let data = event.data ? event.data.json() : { title: 'New!', content: 'Something new happened!', url: '/' };
|
||||
let data = event.data
|
||||
? event.data.json()
|
||||
: { title: 'New!', content: 'Something new happened!', url: '/' };
|
||||
|
||||
const options = {
|
||||
body: data.content,
|
||||
|
||||
Reference in New Issue
Block a user