How to modify .htaccess to serve brotli compressed static assets over gziped ones? I'm trying to use brotli compressed static assets with Advanced CSS/JS Aggregation as detailed here, https://www.drupal.org/node/2773807. The assets are created as they should be, but they're never served because the .htaccess file doesn't know to do that. 

lyncd.com has a short walkthrough, https://lyncd.com/2015/11/brotli-support-apache/, but I haven't been able to munge their code into Drupal's.

Here' the lyncd.com example:

    FileETag None

    &lt;Files *.js.gz&gt;
      AddType "text/javascript" .gz
      AddEncoding gzip .gz
    &lt;/Files&gt;
    &lt;Files *.css.gz&gt;
      AddType "text/css" .gz
      AddEncoding gzip .gz
    &lt;/Files&gt;

    &lt;Files *.js.br&gt;
      AddType "text/javascript" .br
      AddEncoding br .br
    &lt;/Files&gt;
    &lt;Files *.css.br&gt;
      AddType "text/css" .br
      AddEncoding br .br
    &lt;/Files&gt;

    RewriteEngine On

    RewriteCond %{HTTP:Accept-Encoding} br
    RewriteCond %{REQUEST_FILENAME}.br -f
    RewriteRule ^(.*)$ $1.br [L]

    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteCond %{REQUEST_FILENAME}.gz -f
    RewriteRule ^(.*)$ $1.gz [L]


And here's the 7.50 .htaccess bit:

    # Rules to correctly serve gzip compressed CSS and JS files.
    # Requires both mod_rewrite and mod_headers to be enabled.
    &lt;IfModule mod_headers.c&gt;
      # Serve gzip compressed CSS files if they exist and the client accepts gzip.
      RewriteCond %{HTTP:Accept-encoding} gzip
      RewriteCond %{REQUEST_FILENAME}\.gz -s
      RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

      # Serve gzip compressed JS files if they exist and the client accepts gzip.
      RewriteCond %{HTTP:Accept-encoding} gzip
      RewriteCond %{REQUEST_FILENAME}\.gz -s
      RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

      # Serve correct content types, and prevent mod_deflate double gzip.
      RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
      RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]

      &lt;FilesMatch "(\.js\.gz|\.css\.gz)$"&gt;
        # Serve correct encoding type.
        Header set Content-Encoding gzip
        # Force proxies to cache gzipped &amp; non-gzipped css/js files separately.
        Header append Vary Accept-Encoding
      &lt;/FilesMatch&gt;
    &lt;/IfModule&gt;


With your powers combined we can make the web about 20% cooler!
Give this a try

# Rules to correctly serve gzip compressed CSS and JS files.
# Requires both mod_rewrite and mod_headers to be enabled.
&lt;IfModule mod_headers.c&gt;
  # Serve brotli compressed CSS files if they exist and the client accepts gzip.
  RewriteCond %{HTTP:Accept-encoding} br
  RewriteCond %{REQUEST_FILENAME}\.br -s
  RewriteRule ^(.*)\.css $1\.css\.br [QSA]

  # Serve gzip compressed CSS files if they exist and the client accepts gzip.
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{REQUEST_FILENAME}\.gz -s
  RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

  # Serve brotli compressed JS files if they exist and the client accepts gzip.
  RewriteCond %{HTTP:Accept-encoding} br
  RewriteCond %{REQUEST_FILENAME}\.br -s
  RewriteRule ^(.*)\.js $1\.js\.br [QSA]

  # Serve gzip compressed JS files if they exist and the client accepts gzip.
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{REQUEST_FILENAME}\.gz -s
  RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

  # Serve correct content types, and prevent mod_deflate double gzip.
  RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
  RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
  RewriteRule \.css\.br$ - [T=text/css,E=no-gzip:1]
  RewriteRule \.js\.br$ - [T=text/javascript,E=no-gzip:1]

  &lt;FilesMatch "(\.js\.gz|\.css\.gz)$"&gt;
    # Serve correct encoding type.
    Header set Content-Encoding gzip
    # Force proxies to cache gzipped &amp; non-gzipped css/js files separately.
    Header append Vary Accept-Encoding
  &lt;/FilesMatch&gt;
  &lt;FilesMatch "(\.js\.br|\.css\.br)$"&gt;
    # Serve correct encoding type.
    Header set Content-Encoding br
    # Force proxies to cache gzipped &amp; non-gzipped css/js files separately.
    Header append Vary Accept-Encoding
  &lt;/FilesMatch&gt;
&lt;/IfModule&gt;