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 <noreply@anthropic.com>
This commit is contained in:
@@ -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(
|
||||
'<html><body style="font-family:system-ui;text-align:center;padding:60px 20px;background:#1a1a1a;color:#ccc">' +
|
||||
'<h2>LED Grab</h2><p>Cannot reach the server. Check that it is running and you are on the same network.</p>' +
|
||||
'<button onclick="location.reload()" style="margin-top:20px;padding:10px 24px;border-radius:8px;border:none;background:#4CAF50;color:#fff;font-size:1rem;cursor:pointer">Retry</button>' +
|
||||
'</body></html>',
|
||||
{ status: 503, headers: { 'Content-Type': 'text/html' } }
|
||||
)
|
||||
)
|
||||
);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user