1

I am working on a Flutter web application hosted on AWS CloudFront and have encountered an issue related to file compression. My JavaScript files are being correctly compressed with Brotli, but for some reason, my WebAssembly (.wasm) files, specifically those in the /canvaskit/ directory, are only being compressed with Gzip. I'd like to use Brotli for these files due to its superior compression ratios.

To tackle this, I've written a CloudFront function with the intent to enforce Brotli compression for these .wasm files. Here's the pertinent part of my function:

var headers = request.headers;

// Force the use of Brotli compression for CanvasKit files.
if (uri.startsWith('/canvaskit/')) {
  headers['accept-encoding'] = {value: 'br'};
}

I was expecting that after implementing this change, the CloudFront would apply Brotli compression to these .wasm files. However, not only did CloudFront not switch to Brotli for these files, but it also stopped compressing these files altogether, which is an entirely new problem I need to resolve.

Can anyone shed light on why CloudFront is not using Brotli compression for my .wasm files and how I can fix it? Additionally, why would modifying the Accept-Encoding header to 'br' cause CloudFront to stop compressing these files entirely? Any insights would be greatly appreciated.

Thank you in advance for your help!

jperezr21
  • 11
  • 1
  • 3
  • Have you tried adding a cache behavior for `/canvaskit/*` (or `/*.wasm` if you prefer) that has a cache policy with only Brotli compression enabled? You'll need to remove this CloudFront Function. – Cristian Jul 10 '23 at 18:05
  • Hi @Cristian! Thanks for the suggestion. Tried doing that (created a cache policy specifically for `/*.wasm` with Brotli compression enabled and Gzip disabled) and the result is the same: wasm files are not being compressed at all. – jperezr21 Jul 12 '23 at 22:16

0 Answers0