/* Foodlinkk PWA — light cache for shell */ const CACHE = 'foodlinkk-v1'; const ASSETS = [ '/', '/static/css/palantir-theme.css', '/static/css/pulse-theme.css', '/static/css/mobile.css', '/static/css/vertical-tabs.css', '/static/js/cockpit.js', '/static/js/live-pulse.js', '/static/icons/app-icon.svg', '/static/manifest.json', ]; self.addEventListener('install', (e) => { e.waitUntil( caches.open(CACHE).then((c) => c.addAll(ASSETS).catch(() => {})) ); self.skipWaiting(); }); self.addEventListener('activate', (e) => { e.waitUntil( caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))) ) ); self.clients.claim(); }); self.addEventListener('fetch', (e) => { if (e.request.method !== 'GET') return; const url = new URL(e.request.url); if (url.pathname.startsWith('/api/') || url.pathname.startsWith('/ws')) return; e.respondWith( fetch(e.request) .then((r) => { if (r.ok && url.pathname.startsWith('/static/')) { const clone = r.clone(); caches.open(CACHE).then((c) => c.put(e.request, clone)); } return r; }) .catch(() => caches.match(e.request).then((m) => m || caches.match('/'))) ); });