1

I'm hosting a single page static website on Google cloud and I'm trying to implement text-compression on my index.html file.

What I've done so far was to copy all my minified html code from index.html and convert it to Brotli code using an online converter and then saving the Brotli code as index2.html in my bucket. Finally I set the Content-encoding meta value of index2.html to br.

How ever, despite my expectation, I only see a blank page in Chrome and "Content Encoding Error" in Firefox when i go to the www.mysite.com/index2.html address.

I also did the same procedure with gzip compression and setting the content-encoding to gzip but the results were the same. I used the following instructions by Google but it doesn't seem very comprehensive.

What am I doing wrong?

P.S. I am using HTTPS with a valid SSL. I also ckecked in my browser, and the server sent a header that includes the gzip and br in the content-encoding field.

  • 1
    Normally the web server handles compression transparently for you. You don't have to compress the files yourself. Could you check the content-encoding in the response header when accessing index.html? – jkoch Mar 16 '22 at 22:14
  • @jkoch Apparently google cloud isn't doing any compression by itself since the size of the file doesn't change if I only suffice to set a content-encoding. I checked and index.html has no content-encoding in response header. It just has a 'Accept-Encoding: gzip, deflate, br' in the request header. I didn't compress anything in index.html. I made index2.html temporarily just to make a practice compression first and then work my way to the real index.html. – Babak Accuracy Mar 16 '22 at 23:01

1 Answers1

1

It almost (!) works for me but not how I expect it to and I'm unclear why.

I have a (JPEG) file ${IMAGE} in a bucket that's hosting a website.

  1. Copy the image locally
  2. brotli it
  3. Copy the brotli'd image back to the bucket
  4. Set its metadata
  5. Browse it.
gsutil cp gs://${BUCKET}/images/${IMAGE} ${PWD}

brotli ${IMAGE} --output=brotli.jpg

gsutil cp brotli.jpg gs://${BUCKET}/images

gsutil setmeta \
  -h "Content-Type:image/jpeg" \
  -h "Content-Encoding:br" \
  gs://${BUCKET}/images/brotli.jpg

gsutil stat gs://${BUCKET}/images/brotli.jpg 
    Content-Encoding:       br
    Content-Type:           image/jpeg

If I browse the site directly in Chrome, it fails (canceled) no response code:

ERR_CONTENT_DECODING_FAILED

If I browse the GCS public URL, it works (200):

https://storage.googleapis.com/${BUCKET}/images/brotli.jpg

And:

https://storage.cloud.google.com/${BUCKET}/images/brotli.jpg

If I use gzip rather than brotli, both work as expected.

For some reason, I'm unable to browse a brotli compressed file as part of the static site even though it's definitively present and I can browse the URL via other means.

DazWilkin
  • 32,823
  • 5
  • 47
  • 88
  • I'm doing the exact same procedure for a HTML file. I Brotli the text inside html and save it as a html file, upload it into my bucket, and set the metadata, but I'm not able to browse it. – Babak Accuracy Mar 17 '22 at 05:23
  • It may be worth raising on Goggle's public [issue tracker](https://issuetracker.google.com) – DazWilkin Mar 17 '22 at 13:30
  • Aha! https://stackoverflow.com/a/40782162/609290 – DazWilkin Mar 17 '22 at 16:15
  • I noticed today that Chrome DevTools showed the request to a brotli-encoding file doesn't include `Accept-Encoding: br` and a quick Google turned up that issue. Websites hosted on GCS buckets default to HTTP (in my case) explaining the issue. – DazWilkin Mar 17 '22 at 16:16
  • No matter what browser I use results are the same. Are you suggesting it has something to do with the GCS Bucket? – Babak Accuracy Mar 18 '22 at 04:01
  • I assume other browsers are requiring HTTPs similarly. This also explains why the public and authenticated URLs work as they're both HTTPs. – DazWilkin Mar 18 '22 at 04:16
  • Yes but it still doesn't explain why Brotli compression doesn't work as expected. – Babak Accuracy Mar 19 '22 at 23:40