Plainnotes

Precompressed static files cost nothing at runtime

2023-12-20 · 2 min readDeploy

Compressing on the fly costs CPU; static files can be compressed at build time.

gzip -9 -k assets/*.css assets/*.js
gzip_static on;

A request for app.css serves app.css.gz if it exists, with no CPU cost. gzip_static always; sends it even to clients that did not ask — rarely wanted.

Keep Vary: Accept-Encoding and a correct Content-Encoding so caches do not mix representations.

Brotli works the same way with brotli_static on; and the module installed; .br files are typically another 15% smaller.

Make sure the build pipeline includes the step. If a deploy forgets it, nginx falls back to the original silently — no error, just no benefit.