fix(web): give static assets a validator caches can check
The front-end was served with `no-cache` but no `ETag` and no `Last-Modified`, so a cache had nothing to revalidate against and could keep handing out modules older than the API they talk to — which surfaces as a cryptic error in a view rather than as anything resembling a stale cache. Assets now carry both, and an unchanged file answers 304. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
3 files changed
+35
-2
No files matched your search
@@ -95,6 +95,27 @@ describe('dashboard server', () => {
|
||||
assert.match(response.headers.get('content-type'), /javascript/);
|
||||
});
|
||||
|
||||
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');
|
||||
assert.ok(response.headers.get('last-modified'), 'no Last-Modified on a static asset');
|
||||
});
|
||||
|
||||
it('answers 304 when the cached copy is still current', async () => {
|
||||
const first = await app.fetch('/core/dom.js');
|
||||
const etag = first.headers.get('etag');
|
||||
|
||||
const second = await app.fetch('/core/dom.js', { headers: { 'If-None-Match': etag } });
|
||||
assert.equal(second.status, 304);
|
||||
assert.equal(await second.text(), '');
|
||||
});
|
||||
|
||||
it('sends the file again when the validator does not match', async () => {
|
||||
const response = await app.fetch('/core/dom.js', { headers: { 'If-None-Match': '"stale"' } });
|
||||
assert.equal(response.status, 200);
|
||||
assert.ok((await response.text()).length > 0);
|
||||
});
|
||||
|
||||
it('sends the security headers on every response', async () => {
|
||||
const response = await app.fetch('/');
|
||||
assert.equal(response.headers.get('x-frame-options'), 'DENY');
|
||||
|
||||
Reference in new issue
Block a user