From 793238b56238901020b6275f49ffa826c08aed4d Mon Sep 17 00:00:00 2001 From: kamaji Date: Sat, 7 Feb 2026 22:03:31 -0600 Subject: [PATCH] Add offline fallback page to service worker Safari intercepts bare 503 responses and shows its native "not connected" error. Return a styled HTML offline page with status 200 so the SW handles it instead of Safari. Co-Authored-By: Claude Opus 4.6 --- app/static/sw.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/app/static/sw.js b/app/static/sw.js index 4b4e58d..fe576ab 100644 --- a/app/static/sw.js +++ b/app/static/sw.js @@ -1,9 +1,28 @@ // NextSnap Service Worker // Provides offline-first caching for the app shell -const CACHE_VERSION = 'nextsnap-v19'; -const APP_SHELL_CACHE = 'nextsnap-shell-v15'; -const RUNTIME_CACHE = 'nextsnap-runtime-v15'; +const CACHE_VERSION = 'nextsnap-v20'; +const APP_SHELL_CACHE = 'nextsnap-shell-v16'; +const RUNTIME_CACHE = 'nextsnap-runtime-v16'; + +// Offline fallback page (served when network fails and no cached version exists) +const OFFLINE_PAGE = ` + + +Offline - NextSnap + +

You're Offline

Check your internet connection and try again.

+
+`; // Assets to cache on install const APP_SHELL_ASSETS = [ @@ -128,7 +147,10 @@ self.addEventListener('fetch', (event) => { { status: 503, headers: { 'Content-Type': 'application/json' } } ); } - return new Response('Offline', { status: 503 }); + return new Response(OFFLINE_PAGE, { + status: 200, + headers: { 'Content-Type': 'text/html' } + }); }); }) );