diff --git a/config/pwa.ts b/config/pwa.ts index 46c0a066..43b4f5a7 100644 --- a/config/pwa.ts +++ b/config/pwa.ts @@ -14,7 +14,7 @@ export const pwa: VitePWANuxtOptions = { manifest: false, injectManifest: { globPatterns: ['**/*.{js,json,css,html,txt,svg,png,ico,webp,woff,woff2,ttf,eot,otf,wasm,webmanifest}'], - globIgnores: ['emojis/**'], + globIgnores: ['emojis/**', 'shiki/**'], }, devOptions: { enabled: process.env.VITE_DEV_PWA === 'true', diff --git a/service-worker/sw.ts b/service-worker/sw.ts index c2553a53..5d139b09 100644 --- a/service-worker/sw.ts +++ b/service-worker/sw.ts @@ -36,6 +36,19 @@ if (import.meta.env.PROD) // only cache pages and external assets on local build + start or in production if (import.meta.env.PROD) { + // include shiki cache + registerRoute( + ({ sameOrigin, url }) => + sameOrigin && url.pathname.startsWith('/shiki/'), + new StaleWhileRevalidate({ + cacheName: 'elk-shiki', + plugins: [ + new CacheableResponsePlugin({ statuses: [200] }), + // 365 days max + new ExpirationPlugin({ maxAgeSeconds: 60 * 60 * 24 * 365 }), + ], + }), + ) // include emoji icons registerRoute( ({ sameOrigin, request, url }) =>