perf(static): serve the hashed assets from Brotli copies written at build time

Every file under assets/ was compressed again on each download, at the low
level a request path can afford. They carry their content hash in the name
and never change, so the client build now writes a Brotli copy beside each
compressible one (postbuild, scripts/precompress.mjs) and production points
a browser that accepts Brotli at that copy before express.static serves it.

Measured on a production build of 5.1.2, fetching the 652 precached files
the way a service worker install does: 16.3 MB -> 13.9 MB on the wire and
about 1.0 s -> 0.2 s of server CPU per install. A client without Brotli, a
range request and a build without copies are served exactly as before.
This commit is contained in:
John Jahn
2026-11-10 15:03:28 -05:00
committed by Maurice
parent a9d11ccb2e
commit 04b1fb72bb
9 changed files with 314 additions and 2 deletions
@@ -552,6 +552,9 @@ describe('applyPlatformStatic', () => {
expect(header('/app/public/sw.js')).toBeUndefined();
expect(header('/app/public/icons/icon-192.png')).toBeUndefined();
expect(header('/app/public/assets/plain.js')).toBeUndefined();
// The Brotli copy of a hashed file (precompressed-static.ts) never changes either.
expect(header('/app/public/assets/index-DbM4_q2x.js.br')).toBe('public, max-age=31536000, immutable');
expect(header('/app/public/sw.js.br')).toBeUndefined();
});
});