Improve document caching strategy for offline navigation

- Add navigateFallbackDenylist to exclude API and auth routes
- Enhanced urlPattern to match document destination and root path
- Increase cache entries to 50 and duration to 7 days
- Add cacheableResponse for better cache control

This should enable the app to open offline after being loaded once.
This commit is contained in:
2025-10-13 02:34:14 -06:00
parent e59f7b653d
commit ec9ccece61

View File

@@ -73,6 +73,7 @@ export default defineNuxtConfig({
}, },
workbox: { workbox: {
navigateFallback: '/', navigateFallback: '/',
navigateFallbackDenylist: [/^\/api\//, /^\/authentik\//],
globPatterns: ['**/*.{js,css,html,png,svg,ico,json}'], globPatterns: ['**/*.{js,css,html,png,svg,ico,json}'],
cleanupOutdatedCaches: true, cleanupOutdatedCaches: true,
runtimeCaching: [ runtimeCaching: [
@@ -81,14 +82,21 @@ export default defineNuxtConfig({
handler: 'NetworkOnly' handler: 'NetworkOnly'
}, },
{ {
urlPattern: ({ request }) => request.mode === 'navigate', urlPattern: ({ url, request }) => {
return request.destination === 'document' ||
request.mode === 'navigate' ||
url.pathname === '/'
},
handler: 'NetworkFirst', handler: 'NetworkFirst',
options: { options: {
cacheName: 'pages-cache', cacheName: 'pages-cache',
networkTimeoutSeconds: 3, networkTimeoutSeconds: 3,
expiration: { expiration: {
maxEntries: 10, maxEntries: 50,
maxAgeSeconds: 60 * 60 * 24 // 24 hours maxAgeSeconds: 60 * 60 * 24 * 7 // 7 days
},
cacheableResponse: {
statuses: [0, 200]
} }
} }
} }