Brotli Pre-compression for Only One Account

Alec Dean

Registered
Oct 23, 2017
2
0
1
Budapest
cPanel Access Level
Root Administrator
Hi Guys...

I'd like to enable Brotli pre-compression for just one of my accounts who will actually be taking the time to manually Brotli compress their static assets. In reference to this thread: Using Brotli to pre-compress content, I'm clear that the general pre-compression entry needs to be added to the WHM >> Apache Configuration >> Pre VirtualHost Include section. What I'd like to know is if I could use an approach similar to the one seen here: mod_brotli - Apache HTTP Server Version 2.5 Where the compression is restricted to a particular directory to also limit the pre-compression to just one account? Something like:
Code:
<Directory "/home/account_name/public_html">              
    <IfModule mod_headers.c>
        # Serve brotli compressed CSS and JS files if they exist
        # and the client accepts brotli.
        RewriteCond "%{HTTP:Accept-encoding}" "br"
        RewriteCond "%{REQUEST_FILENAME}\.br" "-s"
        RewriteRule "^(.*)\.(js|css)"              "$1\.$2\.br" [QSA]

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

        <FilesMatch "(\.js\.br|\.css\.br)$">
          # Serve correct encoding type.
          Header append Content-Encoding br

          # Force proxies to cache brotli &
          # non-brotli css/js files separately.
          Header append Vary Accept-Encoding
        </FilesMatch>
    </IfModule>
</Directory>
If so, is <Directory> tag recursive? Will this directive apply to any and all content in the public_html directory and/or any of its subdirectories?

Thanks,
Alec
 

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,911
2,234
363
cPanel Access Level
DataCenter Provider
Twitter
Hello @Alec Dean,

You can edit the file below to modify the default configuration settings for mod_brotli:

/etc/apache2/conf.d/brotli.conf

Then, rather than globally enabling your custom entry for all accounts via the use of the Apache Pre VirtualHost Include, you could instead add the custom entry to the individual VirtualHost of a specific domain using the instructions documented on the link below:

Modify Apache Virtual Hosts with Include Files - EasyApache 4 - cPanel Documentation

Additionally, you may want to vote for the feature request below:

Configure Brotli per-account

Let me know if this helps.

Thank you.