With gzip on, nginx compresses a CSS or JS file again for every visitor, at a modest level to save CPU. For files that never change between deploys, you can compress them once at the highest level and let nginx send those.
gzip -k -9 dist/app.css dist/app.js
location /assets/ {
root /srv;
gzip_static on;
}
-k keeps the original next to app.css.gz. When a browser sends Accept-Encoding: gzip, nginx looks for the .gz file and serves it with Content-Encoding: gzip; clients without gzip get the plain file. Deliberately different content in the two files shows which one comes back, and nginx picks the right one each time.
It needs the http_gzip_static_module. The official Docker image and most distribution packages have it; nginx -V shows --with-http_gzip_static_module if yours does.
nginx does not compare the two files. If your build step updates app.css but leaves an old app.css.gz, visitors with gzip get the old version, which is a confusing bug. I’d make the compress step part of the build and delete stale .gz files in the same run. Keep plain gzip on as well for dynamic responses. Brotli is not included in the stock nginx build, so .br files need an extra module.
Further reading: ngx_http_gzip_static_module
Going deeper: 🛜 Guide: AdGuard Home + Tailscale (Secure Split-Horizon DNS)