Options for Brotli Compression Using Cloudfront and S3

When using AWS S3 as an origin to serve a static website distributed by AWS Cloudfront you need to choose how to enable brotli compression. These choices are mutually exclusive—you can either a) have Cloudfront compress to brotli at the edge with a 20% ratio with fallbacks for gzip or no compression or b) compress to brotli by pre-compressing assets where you can use a much higher ratio (80%), but with no fallbacks.

As an alternative you can use AWS Lambda Edge to rewrite requests based on the Accept-Encoding header, but then you need to pay for that in addition to S3 and Cloudfront costs.d

See also: