const CACHE_NAME = 'mischlabs-pwa-v16'; const APP_SHELL = [ '/', '/index.html', '/favorites.html', '/offline.html', '/style.css?v=28', '/auth.js?v=1', '/app.js?v=33', '/favorites.js?v=1', '/services.json?v=1', '/manifest.webmanifest?v=4', '/favicon.ico?v=4', '/icons/favicon-32-v4.png', '/icons/favicon-192-v4.png', '/icons/favicon-512-v4.png', '/icons/apple-touch-icon-v4.png', '/icons/maskable-512-v4.png' ]; self.addEventListener('install', (event) => { event.waitUntil( caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL)) ); 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; if (request.method !== 'GET') { return; } if (request.mode === 'navigate') { event.respondWith( fetch(request).catch(() => caches.match('/offline.html')) ); return; } event.respondWith( caches.match(request).then((cached) => ( cached || fetch(request).then((response) => { if (!response || response.status !== 200 || response.type !== 'basic') { return response; } const responseToCache = response.clone(); caches.open(CACHE_NAME).then((cache) => cache.put(request, responseToCache)); return response; }) )) ); });