From 3f4a5709cfbba60db482ddf6584d12e5bfd2aea0 Mon Sep 17 00:00:00 2001 From: nocode Date: Wed, 23 Sep 2026 22:49:42 +0200 Subject: [PATCH] fix(web): stop caching the interface modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modules cache independently, so a browser could revalidate one and keep an older copy of another — leaving a page running one version of itself and a different version of its helpers. That surfaces as an error inside a feature, which is nothing like what it is, and no reload short of clearing the site data reliably fixes it. A dashboard is a handful of small files read by one person at a time: the bandwidth caching saves is worth less than the failure it causes. They are now fetched fresh. Co-Authored-By: Claude Opus 5 (1M context) --- src/web/http.js | 10 ++++++++-- tests/web-server.test.js | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) 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');