PERF: Enable brotli in NGINX (#32333)

This enables on-the-fly brotli compression at level 4 for all responses
which we currently gzip. This level should provide slightly improved
file sizes when compared to gzip, as well as slightly faster processing
times. This is the [level which Cloudflare
use](https://blog.cloudflare.com/results-experimenting-brotli/) for
dynamic responses.

When compared to our existing gzip level-5 configuration, our own
experiments confirm that it provides slightly faster compression, with
slightly smaller file sizes.

For static assets which are cached by CDNs/browsers, we use brotli level
6 for an even better compression ratio.
This commit is contained in:
David Taylor 2025-04-24 15:45:13 +01:00 committed by GitHub
parent fe12500767
commit c38b50994d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -54,6 +54,11 @@ server {
gzip_types application/json text/css text/javascript application/x-javascript application/javascript image/svg+xml application/wasm font/ttf font/otf; gzip_types application/json text/css text/javascript application/x-javascript application/javascript image/svg+xml application/wasm font/ttf font/otf;
gzip_proxied any; gzip_proxied any;
brotli on;
brotli_min_length 1000;
brotli_comp_level 4;
brotli_types application/json text/css text/javascript application/x-javascript application/javascript image/svg+xml application/wasm font/ttf font/otf;
server_name _; server_name _;
server_tokens off; server_tokens off;
@ -225,6 +230,8 @@ server {
# acceleration for backups, avatars, sprites and so on. # acceleration for backups, avatars, sprites and so on.
# see note about repetition above # see note about repetition above
location ~ ^/(svg-sprite/|letter_avatar/|letter_avatar_proxy/|user_avatar|highlight-js|stylesheets|theme-javascripts|favicon/proxied|service-worker|extra-locales/) { location ~ ^/(svg-sprite/|letter_avatar/|letter_avatar_proxy/|user_avatar|highlight-js|stylesheets|theme-javascripts|favicon/proxied|service-worker|extra-locales/) {
brotli_comp_level 6;
# if Set-Cookie is in the response nothing gets cached # if Set-Cookie is in the response nothing gets cached
# this is double bad cause we are not passing last modified in # this is double bad cause we are not passing last modified in
proxy_ignore_headers "Set-Cookie"; proxy_ignore_headers "Set-Cookie";