mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 15:51:00 +00:00
04b1fb72bb
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.
13 lines
617 B
JavaScript
13 lines
617 B
JavaScript
#!/usr/bin/env node
|
|
/*
|
|
* postbuild: writes a Brotli copy beside every compressible file under dist/assets,
|
|
* which the server hands to a browser that accepts Brotli instead of compressing
|
|
* the file again on each download. scripts/lib/precompress.mjs holds the work.
|
|
*/
|
|
import { fileURLToPath } from 'node:url';
|
|
import { precompress } from './lib/precompress.mjs';
|
|
|
|
const { files, before, after } = precompress(fileURLToPath(new URL('../dist/assets', import.meta.url)));
|
|
const mb = (bytes) => (bytes / 1048576).toFixed(1);
|
|
console.log(`precompress: ${files} files, ${mb(before)} MB -> ${mb(after)} MB (brotli)`);
|