Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heartshare/a5fba6bb75d877cff39338b4fd5fb4e4 to your computer and use it in GitHub Desktop.
Save heartshare/a5fba6bb75d877cff39338b4fd5fb4e4 to your computer and use it in GitHub Desktop.
# Static Brotli:
# Browser accepts brotli, and matching pre-compressed file exists => rewrite to .br file
# For each file format set the correct mime type (otherwise brotli mime type is returned) and prevent Nginx for recompressing the files
set $extension "";
if ($http_accept_encoding ~ br) {
set $extension .br;
}
if (-f $request_filename$extension) {
rewrite (.*) $1$extension break;
}
location ~ /*.html.br$ {
gzip off;
brotli off;
#Clearing types
types {}
default_type text/html;
add_header Content-Encoding br;
add_header Vary "Accept-Encoding";
expires max;
}
location ~ /*.css.br$ {
gzip off;
brotli off;
#Clearing types
types {}
default_type text/css;
add_header Content-Encoding br;
add_header Vary "Accept-Encoding";
expires max;
}
location ~ /*.js.br$ {
gzip off;
brotli off;
#Clearing types
types {}
default_type application/javascript;
add_header Content-Encoding br;
add_header Vary "Accept-Encoding";
expires max;
}
location ~ /*.svg.br$ {
gzip off;
brotli off;
#Clearing types
types {}
default_type image/svg+xml;
add_header Content-Encoding br;
add_header Vary "Accept-Encoding";
expires max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment