From e1fbbd4d7ca93031cf04b60aa4d8c23af71727fd Mon Sep 17 00:00:00 2001 From: Hikari Date: Fri, 20 Feb 2026 01:02:59 -0800 Subject: [PATCH] fix: make service worker more resilient to prevent freezing The service worker was causing 503 errors and freezing requests because: - Pre-caching was trying to cache non-existent files - Fetch handler was too aggressive with interception - Failed cache operations blocked all requests Fixes: - Made pre-caching optional (logs errors but doesn't fail) - More lenient fetch handler (only caches successful responses) - Proper error handling for cache operations - Only intercepts GET requests - Falls back to network if cache fails --- apps/frontend/src/service-worker.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/frontend/src/service-worker.js b/apps/frontend/src/service-worker.js index 9078e9e..3ea146a 100644 --- a/apps/frontend/src/service-worker.js +++ b/apps/frontend/src/service-worker.js @@ -11,11 +11,6 @@ const IMAGE_CACHE = `${CACHE_VERSION}-images`; // Static assets to cache on install const STATIC_ASSETS = [ - '/', - '/index.html', - '/main.js', - '/runtime.js', - '/styles.css', '/offline.html' ]; @@ -27,6 +22,8 @@ self.addEventListener('install', (event) => { console.log('[Service Worker] Caching static assets'); return cache.addAll(STATIC_ASSETS).catch((err) => { console.error('[Service Worker] Failed to cache static assets:', err); + // Don't fail installation if caching fails + return Promise.resolve(); }); }).then(() => { return self.skipWaiting(); @@ -137,10 +134,13 @@ self.addEventListener('fetch', (event) => { event.respondWith( fetch(request) .then((response) => { - const responseClone = response.clone(); - caches.open(DYNAMIC_CACHE).then((cache) => { - cache.put(request, responseClone); - }); + // Only cache successful responses + if (response.ok) { + const responseClone = response.clone(); + caches.open(DYNAMIC_CACHE).then((cache) => { + cache.put(request, responseClone); + }); + } return response; }) .catch(() => {