• Resolved rom174

    (@rom174)


    Hello,

    I am trying to serve pre-compressed brotli files (HTML, CSS, JS).
    In the AO cache, I only can generate the gzipped files but it appears that my server/CDN is compressing it on the fly and serving it with brotli, so the .html.gz, .css.gz and .js.gz pre-compressed are useless.

    In order to serve the brotli version, I found this .htaccess rules :
    https://httpd.apache.org/docs/2.4/fr/mod/mod_brotli.html#precompressed

    <IfModule mod_headers.c>
        RewriteCond "%{HTTP:Accept-encoding}" "br"
        RewriteCond "%{REQUEST_FILENAME}\.br" "-s"
        RewriteRule "^(.*)\.css"              "$1\.css\.br" [QSA]
    
        RewriteCond "%{HTTP:Accept-encoding}" "br"
        RewriteCond "%{REQUEST_FILENAME}\.br" "-s"
        RewriteRule "^(.*)\.js"               "$1\.js\.br" [QSA]
    
        RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-brotli:1]
        RewriteRule "\.js\.gz$"  "-" [T=text/javascript,E=no-brotli:1]
    
        <FilesMatch "(\.js\.br|\.css\.br)$">
          Header append Content-Encoding br
    
          Header append Vary Accept-Encoding
        </FilesMatch>
    </IfModule>

    Is this rule the good one to use ?

    I found a lot of documentation discussing mainly about nginx but not so much about apache even if some are saying it is now mainly enabled by hosters.

    I have seen that you added the function to manage brotli compression in autoptimizeCache.php but I can’t make it work.
    I also added this filter you advised to use with no success :
    add_filter( 'autoptimize_filter_cache_create_static_gzip', '__return_true' );

    Can you let me know what I should do in order to create and store the static version of the .br files as it is done with the .gz files.
    Also is there something to do to make Cache Enabler do the same with .html files ?

    Thank you for your help

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    * the .gz files are only created if you have a filter to force AO to create those (autoptimize_filter_cache_create_static_gzip)
    * .br files will only be created if the above filter is active AND the PHP-function brotli_compress (not available by default, it’s a PHP extension).
    * the apache code _looks_ OK, but I’m not an expert πŸ˜‰

    hope this helps,
    frank

    Thread Starter rom174

    (@rom174)

    Ok thank you Frank for your fast support!

    Files served as content-encoded: br doesn’t mean it is activated ?
    Or it can be active but not necessarily be accessed by autoptimize_filter_cache_create_static_gzip ?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Well, if brotli_compress is available and if you have said filter active, then you should see .br files in the autoptimize cache directory. If not then BR encoding is done on server- or CDN-level.

    Thread Starter rom174

    (@rom174)

    The filter is active (.gz are in cache directory but not .br) but I can only see that the files are served as brotli encoded in the response header.
    But how can files be served on the fly by CDN/server with brotli compression and not be accessible by autoptimize_filter_cache_create_static_gzip ? Is it a hoster configuration question ?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    If there are .gz but not .br files in the AO cache dir, then indeed as per CDN/ host/ server configuration they’re re-compressed using brotli and that indeed will be CDN/ host dependant.

    Thread Starter rom174

    (@rom174)

    Okay thanks a lot Frank

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    you’re welcome, feel free to leave a review of the plugin and support here! πŸ™‚

    have a nice day,
    frank

    Thread Starter rom174

    (@rom174)

    I have done this 1 month ago !
    Thanks again

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    forgot to check, thanks πŸ™‚

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Serving Brotli static pre-compressed files’ is closed to new replies.