Created
October 19, 2022 12:59
-
-
Save linuxd3v/37fef2330ffad6459f9557ed83c01888 to your computer and use it in GitHub Desktop.
code snippet for https://bytepursuits.com/nginx-enabling-brotli-compression-with-gzip-deflate-fallback
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
# 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