Skip to content

Instantly share code, notes, and snippets.

@ampaze
Last active September 16, 2023 19:12
Show Gist options
  • Save ampaze/8caac27f88b2c0c8bc77034cfdb7c4d9 to your computer and use it in GitHub Desktop.
Save ampaze/8caac27f88b2c0c8bc77034cfdb7c4d9 to your computer and use it in GitHub Desktop.
Serve static brotli compressed files on nginx without ngx_brotli
For this to work, you need to precompress your files:
> brotli -q 11 file.css file.cssbr
The file extensions needs to end with br without any delimiter, this is to make the nginx config less cumbersome.
map $http_accept_encoding $brotli_supported {
default "";
"~*(^|[, ])br([;, ]|$)" "br";
}
map $brotli_supported $brotli_supported_vary {
default "";
"br" "Accept-Encoding";
}
server {
# ...
location ~ /*.css$ {
# Dynamisches zippen aus, wir wollen static!
gzip off;
default_type text/css;
add_header Content-Encoding $brotli_supported;
add_header Vary $brotli_supported_vary;
try_files $uri$brotli_supported =404;
}
# ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment