Skip to content

Instantly share code, notes, and snippets.

@linuxd3v
Created October 19, 2022 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save linuxd3v/37fef2330ffad6459f9557ed83c01888 to your computer and use it in GitHub Desktop.
Save linuxd3v/37fef2330ffad6459f9557ed83c01888 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