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!