From ec9ccece610606526de77f196ea73d2fd93e056d Mon Sep 17 00:00:00 2001 From: josedario87 Date: Mon, 13 Oct 2025 02:34:14 -0600 Subject: [PATCH] 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. --- nuxt4/nuxt.config.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/nuxt4/nuxt.config.ts b/nuxt4/nuxt.config.ts index 7505cb3..57c730a 100644 --- a/nuxt4/nuxt.config.ts +++ b/nuxt4/nuxt.config.ts @@ -73,6 +73,7 @@ export default defineNuxtConfig({ }, workbox: { navigateFallback: '/', + navigateFallbackDenylist: [/^\/api\//, /^\/authentik\//], globPatterns: ['**/*.{js,css,html,png,svg,ico,json}'], cleanupOutdatedCaches: true, runtimeCaching: [ @@ -81,14 +82,21 @@ export default defineNuxtConfig({ handler: 'NetworkOnly' }, { - urlPattern: ({ request }) => request.mode === 'navigate', + urlPattern: ({ url, request }) => { + return request.destination === 'document' || + request.mode === 'navigate' || + url.pathname === '/' + }, handler: 'NetworkFirst', options: { cacheName: 'pages-cache', networkTimeoutSeconds: 3, expiration: { - maxEntries: 10, - maxAgeSeconds: 60 * 60 * 24 // 24 hours + maxEntries: 50, + maxAgeSeconds: 60 * 60 * 24 * 7 // 7 days + }, + cacheableResponse: { + statuses: [0, 200] } } }