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
|
* - 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 = [
|
const PRECACHE_URLS = [
|
||||||
'/',
|
|
||||||
'/static/css/base.css',
|
'/static/css/base.css',
|
||||||
'/static/css/layout.css',
|
'/static/css/layout.css',
|
||||||
'/static/css/components.css',
|
'/static/css/components.css',
|
||||||
@@ -75,14 +76,17 @@ self.addEventListener('fetch', (event) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Navigation: network-first
|
// Navigation: network-only (page requires auth, no useful offline fallback)
|
||||||
if (event.request.mode === 'navigate') {
|
if (event.request.mode === 'navigate') {
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
fetch(event.request).catch(() =>
|
fetch(event.request).catch(() =>
|
||||||
caches.match('/') || new Response('Offline', {
|
new Response(
|
||||||
status: 503,
|
'<html><body style="font-family:system-ui;text-align:center;padding:60px 20px;background:#1a1a1a;color:#ccc">' +
|
||||||
headers: { 'Content-Type': 'text/plain' },
|
'<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;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user