Support brotli compression of assets

Created on 23 November 2020, about 4 years ago
Updated 30 January 2023, almost 2 years ago

Problem/Motivation

Drupal supports compressing aggregated assets with gzip.
It would be nice to also support brotli, since it provides better performances.

advagg provides this functionality but only on non-aggregated files.

Proposed resolution

AssetDumper could be patched to also create brotli files.

Remaining tasks

I will submit a patch.

User interface changes

A new option will need to be added to /admin/config/development/performance.

Feature request
Status

Needs work

Version

10.1

Component
Asset library 

Last updated about 10 hours ago

No maintainer
Created by

🇫🇷France prudloff Lille

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Custom Commands Failed
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Custom Commands Failed
  • 🇳🇱Netherlands JesperN

    Added rerolls of patch #20 and the non-`.htaccess` version of #22 on Drupal 10.1.x.

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    So taking a look at this

    Could we add it's own test case? Seems some tests had to be updated for it but not sure if it's actually testing.

    Since the schema is updating most likely will need an upgrade path + upgrade path tests.

    If this new setting is required (which seems to be) it will require a change record also

    Thanks!

  • 🇫🇷France andypost

    What if new compression algo will be added to browsers?

    Better to deprecate "gzip" option in favor of "compress" which will be common trigger to produce all possible assets archives.
    Also it could be a sequence of algo to limit :

    compress:
    - gzip
    - brotli
    
    +++ b/core/lib/Drupal/Core/Asset/AssetDumper.php
    @@ -77,6 +77,16 @@ public function dumpToUri(string $data, string $file_extension, string $uri): st
    +    if (extension_loaded('brotli') && \Drupal::config('system.performance')->get($file_extension . '.brotli')) {
    
    +++ b/core/modules/system/config/install/system.performance.yml
    @@ -4,6 +4,7 @@ cache:
     css:
       preprocess: true
       gzip: true
    +  brotli: false
    
    @@ -12,4 +13,5 @@ fast_404:
     js:
       preprocess: true
       gzip: true
    +  brotli: false
    

    Not sure it makes sense to introduce new configuration and without UI, it could re-use "gzip" setting to produce compressed assets using gzip/brotli

  • 🇬🇧United Kingdom catch

    A compress item with a sequence sounds good.

    Having said that we've got the problem that the .htaccess rules can't be configured - they will always need to check in order of likelihood-of-support first. So if we add brotli support to htaccess but it's disabled by the site, the rewrite rules will still look for those files.

    Makes me wonder if we should just do 'compress' as a boolean and write out everything we possibly can.

  • 🇳🇱Netherlands JesperN

    Added rerolls of patches in #24 on Drupal 10.2.x. I think they should also apply on 11.x-dev.

  • 🇳🇱Netherlands JesperN

    Added rerolls of patches in #29 on Drupal 10.2.x.

  • 🇺🇸United States SocialNicheGuru

    Is there a variable we can set in settings.php?

  • 🇫🇷France andypost

    Not sure how tests can cover it but CR should mention update of nginx conf as well

  • Pipeline finished with Failed
    3 months ago
    Total: 110s
    #323298
  • with a new D11 v11.1.0 install,

    i see in generated assets,

    ls -1 web/sites/default/files/css/ | sort | head -n 6
    	css_1A5CXfNop7cNp-NPI4DF_OGMQem-KN6lxj_k9OzGOpU.css
    	css_1A5CXfNop7cNp-NPI4DF_OGMQem-KN6lxj_k9OzGOpU.css.gz
    	css_1ecH70dXxW6SrorXnALqr-8DiJZhZ4g3Y6cBbPZOuEc.css
    	css_1ecH70dXxW6SrorXnALqr-8DiJZhZ4g3Y6cBbPZOuEc.css.gz
    	css_1TuJBQ_3nvA_oZ-1Bd-SoJw7dHab08LO29K2pikMvXw.css
    	css_1TuJBQ_3nvA_oZ-1Bd-SoJw7dHab08LO29K2pikMvXw.css.gz
    	...
    

    , no brotli (.br)

    checking,

    cat ./web/core/modules/system/config/install/system.performance.yml (yaml)                                                                                                                   cache:
    	page:
    		max_age: 0
    	css:
    	preprocess: true
    	gzip: true
    	fast_404:
    	enabled: true
    	paths: '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i'
    	exclude_paths: '/\/(?:styles|imagecache)\//'
    	html: '<!DOCTYPE html><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>'
    	js:
    	preprocess: true
    	gzip: true
    

    status here says "Needs work", and "Remaining tasks: I will submit a patch."

    the MR, #9980 submitted a month ago, is "Ready to merge" and "1 commit will be added to 11.x".
    but has not been merged.

    @prudloff

    what's outstanding?
    what release can this be expected in?

  • Hope this will be added soon...

    It would be great if automatic creation of static gzip and brotli files is also added for all svg files people have in their themes and uploaded files directories. I am now creating those manually on my server.

Production build 0.71.5 2024