Support

Admin Tools

#41092 Cache-Control header disables brotli compression * with cloudflare

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
4.4.6
PHP version
8.3
Admin Tools version
7.5.4 pro

Latest post by nicholas on Thursday, 05 September 2024 16:14 CDT

dwreski

 

After some hours of debugging, I learned that enabling the "Prevent content transformation" in the htaccess maker disables brotli compression because this header is designed to prevent the modification of data (primarily images) in transit, at least with my cloudflare proxy.

<IfModule mod_headers.c>
     Header merge Cache-Control "no-transform"
</IfModule>

I thought it might be a good idea to indicate this in the setting to make people aware, and also to ask if there's a possible work-around to continue to benefit from this header while also being able to serve brotli compressed data. Somehow it doesn't affect gzip compression.

Enabling this feature apparently prevents the content-encoding header from being visible by the browser through cloudflare.

 

 

 

 

 

 

 

nicholas
Akeeba Staff
Manager

First of all, let's take a look at our documentation (https://www.akeeba.com/documentation/admin-tools-joomla/htaccess-maker.html#basic-security):

Prevent content transformation

Enabling this feature instructs proxy servers and caches to not convert your content. For example, certain proxy servers (typically found in mobile networks, businesses and ISPs in congested areas) will attempt to scale and aggressively compress images, CSS and Javascript to save bandwidth. This can lead to several issues, from displayed images being a bit off to your site breaking down because the compressed CSS/JS introduced errors preventing the browser from parsing it correctly. With this feature enabled the cache and proxy servers will be instructed to not do that by setting an HTTP header. If they respect the HTTP header (they should, it's a web standard) such issues are prevented.

For more information please consult the formal web standard document RFC 2616, section 14.9.5

As explained, the header prevents proxies downstream your site from modifying the content. CloudFlare is a proxy. That's the whole point of a CDN setup like what you have with CloudFlare. Your site is not served directly. It's proxied through the CDN.

The content transformation header neither prevents Brotli compression, nor allows Gzip compression. It's your server handling that, and that's configured with a different option, “Automatically compress static resources”. This feature prioritises Brotli compression. If the necessary Apache web server module (mod_brotli) is not enabled, it falls back to Gzip compression. If the necessary Apache web server module for Gzip compression (mod_gzip) is not enabled, no compression takes place. In your case, mod_brotli is not enabled but mod_gzip is enabled, which is why you see Gzip content, but not Brotli content.

So, as you can see, whether Gzip or Brotli is used depends entirely on your web server with your current configuration. After all, you have told CloudFlare to not change the content it gets from your site!

The actual problem you have is that your configuration is diametrically opposite to what you are trying to achieve and how you are trying to achieve it. 

Since you want CloudFlare to handle resizing and compression you need to disable both “Automatically compress static resources” and “Prevent content transformation”. CloudFlare will get the raw, uncompressed data for image, CSS, and JS files. Then, based on your configuration in CloudFlare itself, it will do any kind of resizing, resampling, and compressing you've told it to do before delivering that content to the client.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

dwreski

As explained, the header prevents proxies downstream your site from modifying the content. CloudFlare is a proxy. That's the whole point of a CDN setup like what you have with CloudFlare. Your site is not served directly. It's proxied through the CDN.

Yes, exactly. I do appreciate your more thorough explanation, but that is effectively what I was saying—this header essentially disables Cloudflare's ability to deliver content compressed by the server.

My point was that it is not entirely clear from just "prevent content transformation" what I should expect and that it's related to Cloudflare's ability to deliver my content as I expect.

 

nicholas
Akeeba Staff
Manager

There is a huge difference between explicitly telling a third party they are not allowed to compress content, and affirming that this action prevents the content from being compressed in the first place. I think the biggest problem in understanding what I am saying is that there are some abstract layers and unfamiliar computer terminology involved. So, let me do what I usually do in this case: explain it with a physical world analogue.

You have an envelope with a card in it where you've written your bank account number. You want to give that envelope to your client so they can pay you, but since they're always busy with meetings you have to go through their secretary.

If the envelope is sealed the secretary has no idea what the contents of the envelope are. They know the client is expecting something from you, though. They do not open the envelope. They give it as-is to your client who opens it. The writing on the card is not modified in any way. Your client sees exactly what you sent them.

If the envelope is not sealed, the secretary can open it and inspect the content. They decide that the best thing for the client is to photocopy the card at 400% magnification, putting the photocopy in the envelope instead of your card. They give the client this envelope with the photocopy, but not the original card. Your client sees the enlarged photocopy, not what you sent him. It's a different form of the same content, one that is more appropriate for this client as determined by their secretary without asking you.

However, the fact that you can seal the envelope DOES NOT mean that you cannot make an enlarged photocopy of the card yourself and put that in the envelope instead of the original card.

If the envelope is sealed, just like above, the secretary takes the envelope and gives it to the client as-is. The client sees the enlarged photocopy. This is the same content as the card (which you have, not the client) but in a format you determined is best for the client.

If the envelope is not sealed, just like above, the secretary takes the envelope, and inspects the content. The content is deemed to be in the preferred form for the client, so the client is handed the envelope as is. The client sees the enlarged photocopy. This is the same content as the card (which you have, not the client) but in a format you determined is best for the client.

Therefore, saying that sealing the envelope prevents you from providing an enlarged copy of it is not true. It's common sense.

Likewise, it is common sense that if you do not have access to a photocopier (maybe you were running late and couldn't stop by a copy shop) you cannot do the enlargement yourself. If you've sealed the envelope before handing it over to the secretary you cannot possibly have any reasonable expectation that the secretary would enlarge the card; by sealing the envelope you have explicitly forbidden them from inspecting and modifying the content.

But we don't have office stationary and people, we have binary data and computers, I hear you say. Same difference, I say! Why? Let's see.

"You" are the web server.

The "client" is the web browser.

The "secretary" is CloudFlare.

The "card" is binary data.

The "photocopier" is a piece of software which does Brotli compression.

The "envelope" is an HTTP request.

The envelope's "seal" is the no-transform attribute in the Cache-Control header.

If you rewrite the above story using the computer terminology you now understand what is really going on.

The existence or absence of the no-transform attribute in the Cache-Control header (whether the envelope is sealed) does not control whether Brotli compression (photocopying) is possible or not. It only prevents the caching proxy (secretary) deciding without asking the web server (you) whether to compress the data (make a photocopy).

Nothing stops the web server (you) from applying Brotli compression to the content (replace the card with an enlarged photocopy) before handing the HTTP request (envelope) to the caching proxy (CloudFlare), but for the fact of whether you have mod_brotli enabled (access to a photocopier).

If you do not have mod_brotli enabled (access to a photocopier) you can deliver an HTTP request (envelope) without the no-transform attribute in the Cache-Control HTTP header (unsealed) to CloudFlare (secretary) and it will decide whether it's appropriate to compress it with Brotli (make a photocopy) before delivering it to the web browser (client) without asking the web server (you).

If, however, you do not have mod_brotli enabled (access to a photocopier) AND you deliver an HTTP request (envelope) with the no-transform attribute in the Cache-Control HTTP header (sealed) to CloudFlare (secretary) then it will have no choice but to deliver the uncompressed (non-photocopied) content (card) to the web browser (client) because you have explicitly forbidden it from compressing (photocopying) the content (card).

To make matters more complicated, there are two photocopiers in our computer world: mod_gzip (Gzip compression) and mod_brotli (Brotli compression). If that hurts your brain, think of it in the analogue world example as one photocopier which enlarges to 200%, and one which enlarges to 400%. Maybe you don't have access to the spanking new model that does 400% magnification (Brotli), but only the older model that does 200% magnification (Gzip). You can put the 200% magnified copy in the envelope. If the envelope is sealed the secretary can't do crap about it, your client gets the 200% magnified copy. If, however, you leave the envelope unsealed, the secretary can blow it up to 400% magnification of the original.

If I put it this way do you understand why you got Gzip compression but not Brotli?

Again.

Whether we seal the envelope or not does not have any impact on our ability to put the original, a 200% magnified, or a 400% magnified copy of the content in it. Only our access to a photocopier, and which photocopier, has an impact. The envelope seal only controls whether the secretary can open the envelope and decide for themselves whether to replace its contents with a photocopy without asking us.

Whether we use "Prevent content transformation" or not does not have any impact on our ability to put the original, a Gzip compressed, or a Brotli compressed content representation in our HTTP response. Only our access to a compression module for Apache, and whether that's mod_gzip or mod_brotli, does. "Prevent content transformation" only controls whether CloudFlare can replace the file contents with a compressed version without asking the web server.

That's a fine but CRUCIAL distinction. Disabling "Prevent content transformation" IS NOT a requirement for Brotli compression. Install and enable mod_brotli in Apache and you'll have Brotli compressed data. The ONLY reason you need to disable "Prevent content transformation" in your specific use case is because you do not have mod_brotli in Apache and you cannot have mod_brotli in Apache, therefore you have to let CloudFlare do the compression itself. Only in your SPECIFIC USE CASE do you need to disable "Prevent content transformation" to allow CloudFlare to transform (compress) your content.

You do not have access to the good photocopier. Therefore, you must leave the envelope unsealed so that the secretary can make a larger photocopy for your client. If you had access to a good photocopier you wouldn't need to leave that envelope unsealed.

Is that clear now?

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

dwreski

The existence or absence of the no-transform attribute in the Cache-Control header (whether the envelope is sealed) does not control whether Brotli compression (photocopying) is possible or

Again, I really appreciate your thorough and descriptive explanation. I was speaking in more abstract terms from the perspective of an end-user of your product, not an engineer (*also my day job). I'm fully aware of how Cloudflare works, and I probably should have clarified that.

Enabling the cache-control header in this way effectively prevents Cloudflare from being able to compress the stream by design. I was merely commenting that the description may not be clear to an everyday user that we're talking about modifying the stream, not individual components like images, etc.

Only in your SPECIFIC USE CASE do you need to disable "Prevent content transformation" to allow CloudFlare to transform (compress) your content.

Yes, that's why I mentioned it, because the description for the toggle is very esoteric without going into your (very fine) documentation.

 

System Task
system
The ticket information has been edited by Dave Wreski (dwreski).

nicholas
Akeeba Staff
Manager

OK, I am now content we are on the same page indeed.

Have a great evening!

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!