Last active
September 16, 2023 19:12
-
-
Save ampaze/8caac27f88b2c0c8bc77034cfdb7c4d9 to your computer and use it in GitHub Desktop.
Serve static brotli compressed files on nginx without ngx_brotli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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