1

I want to add the following code to my htaccess but it does not work.

# ----------------------------------------------------------------------
# | Brotli pre-compressed content                                      |
# ----------------------------------------------------------------------

# Serve brotli compressed CSS, JS, HTML, SVG, ICS and JSON files
# if they exist and if the client accepts br encoding.
#
# (!) To make this part relevant, you need to generate encoded
# files by your own. Enabling this part will not auto-generate
# brotlied files.
#
# Note that some clients (eg. browsers) require a secure connection
# to request brotli-compressed resources.
# https://www.chromestatus.com/feature/5420797577396224
#
# https://httpd.apache.org/docs/current/mod/mod_brotli.html#precompressed

 <IfModule mod_headers.c>

     RewriteCond %{HTTP:Accept-Encoding} br
     RewriteCond %{REQUEST_FILENAME}\.br -f
     RewriteRule \.(css|ics|js|json|html|svg)$ %{REQUEST_URI}.br [L]

     # Prevent mod_deflate double gzip
     RewriteRule \.br$ - [E=no-gzip:1]

     <FilesMatch "\.br$">

         <IfModule mod_mime.c>
             # Serve correct content types
             AddType text/css              css.br
             AddType text/calendar         ics.br
             AddType text/javascript       js.br
             AddType application/json      json.br
             AddType text/html             html.br
             AddType image/svg+xml         svg.br

             # Serve correct content charset
             AddCharset utf-8 .css.br \
                              .ics.br \
                              .js.br \
                              .json.br
         </IfModule>

         # Force proxies to cache brotlied and non-brotlied files separately
         Header append Vary Accept-Encoding

     </FilesMatch>

     # Serve correct encoding type
     AddEncoding br .br

 </IfModule>

h5bp/html5-boilerplate:dist/.htaccess@master#L897-L949

Does not work in root and also not in pub.

3
  • 1
    it's commented out Commented Feb 19, 2019 at 10:50
  • Philipp is right, you have to uncomment it to make it work.
    – fmsthird
    Commented Feb 19, 2019 at 11:51
  • I know and I already did. Let me update the part ;-) I just forgot to update the part here in the question. The problem is that it does not do anything in the pub or the root .htaccess file. But when we open the br files directly in the browser we get the right encoding and output. It seems it has to do with the way Magento is loading static assets and how the rewrite works.
    – user66934
    Commented Feb 19, 2019 at 13:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.