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:
@@ -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]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user