From 6d3d76982a54a83dab8d8526489c214506300954 Mon Sep 17 00:00:00 2001 From: Pranav Date: Sat, 10 Jan 2026 20:58:13 -0800 Subject: [PATCH] refactor: Remove HTML shell caching for navigation Remove networkFirstWithShellCache - offline shell caching has limited value for a real-time chat app that requires network connectivity. The service worker now only caches static assets (JS, CSS, fonts, images). Co-Authored-By: Claude Opus 4.5 --- app/javascript/service-worker/sw-runtime.js | 36 +-------------------- 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/app/javascript/service-worker/sw-runtime.js b/app/javascript/service-worker/sw-runtime.js index 9fa7a9c2c..906c8962a 100644 --- a/app/javascript/service-worker/sw-runtime.js +++ b/app/javascript/service-worker/sw-runtime.js @@ -52,12 +52,6 @@ self.addEventListener('fetch', event => { if (isAsset) { event.respondWith(cacheFirst(request)); - return; - } - - // Navigation to /app/* → network-first (cache HTML shell as fallback) - if (request.mode === 'navigate' && url.pathname.startsWith('/app')) { - event.respondWith(networkFirstWithShellCache(request)); } }); @@ -87,34 +81,6 @@ async function cacheFirst(request) { } } -async function networkFirstWithShellCache(request) { - const cache = await caches.open(CACHE_NAME); - - try { - const response = await fetch(request); - - // Cache the HTML shell for offline fallback - if (response.ok) { - const html = await response.clone().text(); - if (html.includes('data-sw-cache')) { - cache.put( - '/app', - new Response(html, { - headers: response.headers, - }) - ); - } - } - - return response; - } catch (err) { - // Network failed - return cached shell - const cached = await cache.match('/app'); - if (cached) return cached; - throw err; - } -} - // ============================================================================= // Background Prefetch // ============================================================================= @@ -191,7 +157,7 @@ async function cleanupStaleAssets() { const isAssetPath = url.pathname.startsWith('/vite/assets/') || url.pathname.startsWith('/vite-dev/assets/'); - // Only clean up asset files, keep other cached items (like /app shell) + // Only clean up asset files return isAssetPath && !validUrls.has(request.url); }) .map(request => cache.delete(request));