Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manually gzip files for web and Amazon CloudFront

I have a 3MB .wasm file which I'm trying to compress using gzip and used on Amazon CloudFront. Currently CloudFront doesn't support auto compressing .wasm file types.

I used gzip filename.wasm but the outputted result isn't working in my code when fetched from CloudFront. I read elsewhere that the file is missing some file headers.

So my question is, how can I manually gzip a .wasm file for use on web and fetched from CloudFront?

Thanks!

like image 272
user2028856 Avatar asked Oct 26 '25 09:10

user2028856


1 Answers

You can compress the file with gzip, and upload it to s3 using --content-type application/wasm --content-encoding gzip, without the .gz suffix. When this file is then served through cloudfront, it will be returned gzipped and readable by the browser.

Here is an example using brotli:

WASM_FILE=$(ls dist/ | grep '.wasm$');
brotli-cli dist/*.wasm
BROTLI_FILE=$(ls dist/ | grep wasm.br);
mv dist/$BROTLI_FILE dist/$WASM_FILE

aws s3 cp dist/*.wasm s3://$S3_BUCKET/ \
  --content-encoding br \
  --content-type application/wasm
like image 136
Robert Balicki Avatar answered Oct 29 '25 09:10

Robert Balicki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!