const CACHE_NAME = 'ghostboard-v1'; const ASSETS = [ '/', '/static/images/icon.svg', '/static/manifest.json', 'https://cdn.tailwindcss.com', 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js' ]; self.addEventListener('install', (e) => { e.waitUntil( caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS)) ); }); self.addEventListener('fetch', (e) => { // Network first for HTML (navigation), Cache first for assets if (e.request.mode === 'navigate') { e.respondWith( fetch(e.request).catch(() => { return caches.match(e.request).then(response => { if (response) return response; // Fallback to offline page if I had one, or just root return caches.match('/'); }); }) ); } else { e.respondWith( caches.match(e.request).then((response) => { return response || fetch(e.request); }) ); } });