diff --git a/public/sw.js b/public/sw.js index 6a9bfd6..e539a94 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,5 +1,9 @@ const CACHE = 'director-v1'; -const SHELL = ['/', '/index.html', '/src/main.js', '/src/styles.css']; +// Precache only stable, build-invariant navigation paths. Hashed asset +// bundles (/assets/*) are cached at runtime on first online load by the +// cache-first fetch handler below. (Follow-up: generate a full precache +// list from the Vite build manifest for cold-offline-before-first-visit.) +const SHELL = ['/', '/index.html']; self.addEventListener('install', (e) => { e.waitUntil(caches.open(CACHE).then((c) => c.addAll(SHELL)).then(() => self.skipWaiting())); diff --git a/tests/pwa.test.js b/tests/pwa.test.js index 110bff9..a48fbd0 100644 --- a/tests/pwa.test.js +++ b/tests/pwa.test.js @@ -18,9 +18,15 @@ describe('PWA wiring', () => { expect(js).toContain('serviceWorker'); expect(js).toContain("register('/sw.js')"); }); - it('service worker precaches the shell', () => { + it('service worker precaches only stable shell paths', () => { const sw = readFileSync('public/sw.js', 'utf8'); expect(sw).toContain('addEventListener'); expect(sw).toContain('caches'); + const shellMatch = sw.match(/SHELL\s*=\s*\[([^\]]*)\]/); + expect(shellMatch).not.toBe(null); + const shell = shellMatch[1]; + expect(shell).toContain("'/'"); + expect(shell).toContain("'/index.html'"); + expect(shell).not.toContain('/src/'); }); });