Score:1

Enable Brotli for Apache on Google Cloud Compute Engine website

ls flag

I installed and enabled the Brotli module just fine through SSH. Then, I added this to my port 80 VirtualHost config:

<IfModule mod_brotli.c>
    SetOutputFilter BROTLI_COMPRESS
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-brotli
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript
</IfModule>

After restarting Apache, everything is still served via gzip and not Brotli. Specifically, I see content-encoding: gzip for each text-based file, not content-encoding: br as expected.

Edit: my headers include accept-encoding: gzip, deflate, br so that can't be the problem.

Every tutorial that I've researched has very simple instructions yet gzip insists on being the preferred compression method no matter what I try. Going over the VirtualHost config files, I can't see anything about gzip or compression in them at all so it's odd that adding the above to those config files has no impact at all.

John Hanley avatar
cn flag
1) What is the result from this test: `curl -I -H 'Accept-Encoding: br' URL`? If you see `Content-Encoding: br` then Brotli compression is working. 2) If not, you have a configuration problem. 3) Your request specifies three compression methods. The server has picked one. 4) Try moving `br` to the front of your `accept-encoding` header. 5) Try adding the qualifier `Accept-Encoding: gzip;q=0.5, br;q=1.0` to the request to specify compression preference. Update your question with more details from my comments.
JimmyTheCuck avatar
ls flag
@John I can test the curl command tomorrow. For now, 3/4/5 - it is `accept-encoding: gzip, deflate, br` because that's what's default in Chrome. Does that mean Chrome prefers gzip over Brotli? ie: if a site can serve both, does Chrome decide to request gzip?
John Hanley avatar
cn flag
Yes, the `accept-encoding` header specifies client preference left to right unless a qualifier is added. That means if both the server and client support `gzip` and `gzip` is first, `gzip` will be selected usually. There are other headers that can affect that decision.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.