From 01104acad1f026518b732e70f568bf1d405faabf Mon Sep 17 00:00:00 2001 From: "alexei.dolgolyov" Date: Sun, 1 Mar 2026 14:31:31 +0300 Subject: [PATCH] Fix service worker caching root page without auth Remove '/' from precache list (requires API key, caching it stores an error page). Bump cache to v2 to purge stale caches. Replace offline navigation fallback with a friendly retry page. Co-Authored-By: Claude Opus 4.6 --- server/src/wled_controller/static/sw.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/src/wled_controller/static/sw.js b/server/src/wled_controller/static/sw.js index 1e8643d..e3e6427 100644 --- a/server/src/wled_controller/static/sw.js +++ b/server/src/wled_controller/static/sw.js @@ -7,10 +7,11 @@ * - Navigation: network-first with offline fallback */ -const CACHE_NAME = 'ledgrab-v1'; +const CACHE_NAME = 'ledgrab-v2'; +// Only pre-cache static assets (no auth required). +// Do NOT pre-cache '/' — it requires API key auth and would cache an error page. const PRECACHE_URLS = [ - '/', '/static/css/base.css', '/static/css/layout.css', '/static/css/components.css', @@ -75,14 +76,17 @@ self.addEventListener('fetch', (event) => { return; } - // Navigation: network-first + // Navigation: network-only (page requires auth, no useful offline fallback) if (event.request.mode === 'navigate') { event.respondWith( fetch(event.request).catch(() => - caches.match('/') || new Response('Offline', { - status: 503, - headers: { 'Content-Type': 'text/plain' }, - }) + new Response( + '' + + '

LED Grab

Cannot reach the server. Check that it is running and you are on the same network.

' + + '' + + '', + { status: 503, headers: { 'Content-Type': 'text/html' } } + ) ) ); return;