On Apache, we need to prevent double-compression by mod_brotli (in addition to mod_deflate). See https://httpd.apache.org/docs/2.4/mod/mod_brotli.html

If mod_brotli is enabled and active for text/css and text/javascript, a Drupal site's precompressed CSS and JS cannot be loaded by the browser (Failed to load resource: net::ERR_CONTENT_DECODING_FAILED) so I'm classifying this as a bug rather than feature request.

CommentFileSizeAuthor
#19 2960808-mod_brotli-19.patch1.5 KBmfb
mod_brotli.patch718 bytesmfb

Comments

mfb created an issue. See original summary.

sk33lz’s picture

This original patch applies cleanly to 8.6.x, but I can't seem to get mod_brotli installed to test if this resolves the compression bug.

mfb’s picture

Issue summary: View changes
mfb’s picture

Version: 8.6.x-dev » 8.7.x-dev

Patch still applies on 8.7.x branch

hchonov’s picture

This patch doesn't work for me. I have added the following configuration to the httpd.conf, but the only way to serve css and js is to use deflate instead brotli:

AddOutputFilterByType BROTLI_COMPRESS text/css
AddOutputFilterByType BROTLI_COMPRESS text/javascript
AddOutputFilterByType BROTLI_COMPRESS application/x-javascript application/javascript
mfb’s picture

Make sure you specify BROTLI_COMPRESS before DEFLATE, to set a preference for BROTLI.

This is what I'm using (your mileage may vary as far as which file types you want to compress):

AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml
AddOutputFilterByType DEFLATE         text/html text/plain text/xml
AddOutputFilterByType BROTLI_COMPRESS text/css text/javascript text/calendar
AddOutputFilterByType DEFLATE         text/css text/javascript text/calendar
AddOutputFilterByType BROTLI_COMPRESS application/x-javascript application/javascript application/ecmascript
AddOutputFilterByType DEFLATE         application/x-javascript application/javascript application/ecmascript
AddOutputFilterByType BROTLI_COMPRESS application/rss+xml application/xml
AddOutputFilterByType DEFLATE         application/rss+xml application/xml
AddOutputFilterByType BROTLI_COMPRESS application/json application/json-p
AddOutputFilterByType DEFLATE         application/json application/json-p
AddOutputFilterByType BROTLI_COMPRESS audio/wav audio/x-wav
AddOutputFilterByType DEFLATE         audio/wav audio/x-wav
achikas’s picture

my provider runs ubuntu 18 with brotli compression.
this patch fixed the double compression on Drupal 8.6.2 by adding the following to the .htaccess:

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

Do you think it make sense to add this patch to the core?

mfb’s picture

@achikas if the patch above is working in your testing you could mark it RTBC

eglaw’s picture

I see a different problem here:

based on what i see the performance and CSS/JS aggregation / minification made by core Drupal system is down to 2 formats, the base css_.css and the GZipped version css_.css.gz.

If the system could create 3rd extension css_.css.br (which allows the configured web servers to server brotli compressed files too)

mfb’s picture

@eglaw that is theoretically doable, but few people will have a brotli PHP extension installed so we may be stuck with gzip for some time.

mfb’s picture

yakatz’s picture

I have tested this patch with Apache 2.4.38 (cPanel) and this resolves my issue. Would be great to see it shipped.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Advagg supports brotli also it gives better compression ratio do makes sense to detect the extension and provide BC when it missing

alyaj2a’s picture

Solo puse lo que @achikas dijo, y todo funcionó! Muchas gracias.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

yakatz’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

We need to update core/assets/scaffold/files/htaccess as well - this is the file used for scaffolding when you do composer create-project

mfb’s picture

Status: Needs work » Needs review
StatusFileSize
new1.5 KB
hchonov’s picture

Status: Needs review » Reviewed & tested by the community

I hope there isn't anything else missing.

alexpott’s picture

Priority: Major » Normal
Status: Reviewed & tested by the community » Fixed

Committed and pushed 511b1b69df to 9.0.x and cc43ae66d7 to 8.9.x. Thanks!

As this involves changing .htaccess I don't think we should backport this to 8.8.x since I think people only really want to deal with htaccess changes on minor releases. That said this process gets a bit simpler with the new drupal scaffolding options.

  • alexpott committed 511b1b6 on 9.0.x
    Issue #2960808 by mfb: Disable brotli compression of pre-compressed CSS...

  • alexpott committed cc43ae6 on 8.9.x
    Issue #2960808 by mfb: Disable brotli compression of pre-compressed CSS...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.