self.addEventListener('install', (event) => { event.waitUntil( caches.open('app-cache').then((cache) => { // Use a more robust approach: attempt to cache but don't fail the whole installation if one fails const urlsToCache = [ '/assets/manifest.json', '/assets/favicon.png' ]; return Promise.all( urlsToCache.map(url => { return fetch(url).then(response => { if (response.ok) { return cache.put(url, response); } }).catch(err => console.warn('SW: Failed to cache ' + url, err)); }) ); }) ); }); self.addEventListener('fetch', (event) => { event.respondWith( caches.match(event.request).then((response) => { return response || fetch(event.request); }) ); });