diff --git a/src/web/http.js b/src/web/http.js index 766f9cf..e770e2f 100644 --- a/src/web/http.js +++ b/src/web/http.js @@ -164,8 +164,14 @@ export async function sendStatic(response, root, requestPath, { fallback = null, ...SECURITY_HEADERS, 'Content-Type': MIME_TYPES[extension] ?? 'application/octet-stream', 'Content-Length': info.size, - // The SPA shell must never be cached, its modules are revalidated on each load. - 'Cache-Control': extension === '.html' ? 'no-store' : 'no-cache', + // Every module is fetched fresh rather than revalidated. + // + // A dashboard is a handful of small files loaded by one person at a time, + // so the bandwidth saved by caching is worth less than the failure it + // causes: modules cache independently, so a partial revalidation leaves a + // page running one version of itself and another of its helpers, which + // surfaces as an error inside a feature rather than as a stale cache. + 'Cache-Control': 'no-store', ETag: etag, 'Last-Modified': new Date(info.mtimeMs).toUTCString(), }); diff --git a/tests/web-server.test.js b/tests/web-server.test.js index b55b343..48c4505 100644 --- a/tests/web-server.test.js +++ b/tests/web-server.test.js @@ -95,6 +95,13 @@ describe('dashboard server', () => { assert.match(response.headers.get('content-type'), /javascript/); }); + it('never lets a module be cached, so versions cannot drift apart', async () => { + for (const path of ['/app.js', '/core/ui.js', '/views/settings.js', '/styles.css']) { + const response = await app.fetch(path); + assert.equal(response.headers.get('cache-control'), 'no-store', `${path} peut ĂȘtre mis en cache`); + } + }); + it('gives its assets a validator so a cache can revalidate', async () => { const response = await app.fetch('/core/dom.js'); assert.ok(response.headers.get('etag'), 'no ETag on a static asset');