const CACHE_NAME = 'mpa-projectflow-v2-4-20-login-redesign'; const CORE_ASSETS = [ './offline.html', './assets/style.css?v=2.4.20', './assets/app.js?v=2.4.17', './assets/pwa.js?v=2.4.6', './assets/logo.png', './assets/favicon-192.png', './assets/favicon-32.png', './favicon.ico' ]; self.addEventListener('install', (event) => { event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(CORE_ASSETS)).catch(() => null)); self.skipWaiting(); }); self.addEventListener('activate', (event) => { event.waitUntil(caches.keys().then((keys) => Promise.all(keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key))))); self.clients.claim(); }); self.addEventListener('fetch', (event) => { const request = event.request; const url = new URL(request.url); if (request.method !== 'GET') return; if (url.pathname.endsWith('/api.php') || url.pathname.endsWith('/download.php') || url.pathname.endsWith('/export.php') || url.pathname.endsWith('/po_print.php')) return; event.respondWith( fetch(request).then((response) => { const copy = response.clone(); if (response.ok && (request.destination === 'style' || request.destination === 'script' || request.destination === 'image' || request.destination === 'manifest')) { caches.open(CACHE_NAME).then((cache) => cache.put(request, copy)); } return response; }).catch(() => caches.match(request).then((cached) => cached || caches.match('./offline.html'))) ); });