I want to be able to support Brotli and Gzip encoding for static assets hosted with Google Cloud Storage. To do this I want to encode files before they are uploaded as <filename>, <filename>.gz and <filename>.br. The issue is, I can't find a way to redirect a request with Accept-Encoding to the correct file.
I have looked into using:
- Cloud Functions to somehow redirect incoming requests (similar to AWS Cloudfront Lambda), but it does not seem to be supported
- Load Balancer to redirect requests to different buckets, but as far as I could see it can only redirect based on hostname/path to different buckets
- Cloud CDN, but it does not seem to have any functionality that helps with this
Requests/Response examples
Assume bucket example-bucket contains the following files:
library.js
library.js.gz
library.js.br
Example 1
GET http://storage.googleapis.com/example-bucket/library.js
Accept-Encoding: gzip, deflate, br
Content-Encoding: br
<Contents of http://storage.googleapis.com/example-bucket/library.js.br>
Example 2
GET http://storage.googleapis.com/example-bucket/library.js
Accept-Encoding: gzip, deflate
Content-Encoding: gzip
<Contents of http://storage.googleapis.com/example-bucket/library.js.gz>
Is there a way to accomplish the above in a manner that is simple, performant and cost effective? I realize it's possible to just host my own server via App Engine, and let that take care of routing requests to the bucket, but is this the only way?