From 0965da70b4fe76755adc9c5d838d328fcf41c5d1 Mon Sep 17 00:00:00 2001 From: Frederic Cabassut Date: Thu, 12 Mar 2026 20:16:23 +0100 Subject: [PATCH] fix: enable offline page caching in service worker for PWA refresh support Navigation requests had no caching rule, so refreshing offline showed the browser's default "you are offline" page. Add NetworkFirst runtime caching for navigations (3s timeout), cache Google Fonts for offline use, remove conflicting static webmanifest in favor of the plugin-generated one. Co-Authored-By: Claude Opus 4.6 --- src/app.html | 1 - static/site.webmanifest | 21 --------------------- vite.config.ts | 19 ++++++++++++++++++- 3 files changed, 18 insertions(+), 23 deletions(-) delete mode 100644 static/site.webmanifest diff --git a/src/app.html b/src/app.html index 75406c7..33f3dea 100644 --- a/src/app.html +++ b/src/app.html @@ -11,7 +11,6 @@ - Crumbs %sveltekit.head% diff --git a/static/site.webmanifest b/static/site.webmanifest deleted file mode 100644 index c4b944f..0000000 --- a/static/site.webmanifest +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "Crumbs by Bretzel", - "short_name": "Crumbs", - "icons": [ - { - "src": "/web-app-manifest-192x192.png", - "sizes": "192x192", - "type": "image/png", - "purpose": "maskable" - }, - { - "src": "/web-app-manifest-512x512.png", - "sizes": "512x512", - "type": "image/png", - "purpose": "maskable" - } - ], - "theme_color": "#f9f4ea", - "background_color": "#f9f4ea", - "display": "standalone" -} \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index 085c408..d311771 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -40,8 +40,17 @@ export default defineConfig({ }, workbox: { globPatterns: ['client/**/*.{js,css,ico,png,svg,webp,woff,woff2}'], - navigateFallback: '/', + navigateFallback: null, runtimeCaching: [ + { + urlPattern: ({ request }) => request.mode === 'navigate', + handler: 'NetworkFirst', + options: { + cacheName: 'pages-cache', + networkTimeoutSeconds: 3, + expiration: { maxEntries: 50, maxAgeSeconds: 30 * 24 * 60 * 60 } + } + }, { urlPattern: /\/api\/notes\/.*\/attachments\?attachmentId=/, handler: 'CacheFirst', @@ -57,6 +66,14 @@ export default defineConfig({ cacheName: 'api-cache', expiration: { maxEntries: 50, maxAgeSeconds: 300 } } + }, + { + urlPattern: /^https?:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/, + handler: 'CacheFirst', + options: { + cacheName: 'google-fonts-cache', + expiration: { maxEntries: 10, maxAgeSeconds: 365 * 24 * 60 * 60 } + } } ] }