Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We observed that Amazon Cloudfront was not compressing the Rails WASM download so that the browser was having to transfer 130MB. Chrome was also not caching the file on disk for subsequent page loads.
We first added
Cache-Control
header for the upload to S3 after removing the previous uploads in #5.We then updated the S3 bucket CORS policy to include allow all request headers to satisfy the Cloudfront compressed files requirement that the Origin include the
Content-Length
header.We also learned that the Rails WASM upload is too large to be compressed by Cloudfront, per the Cloudfront docs:
From a StackOverflow answer, we also learned that we could compress eagerly and set the
Content-Encoding
header on the upload.We experimented with different brotli compression levels, i.e.
brotli -q <1-11>
and settled on level 8 compression as a good tradeoff between final compressed size and compression execution time:For
brotli -q <LEVEL> rails-7.1-ruby-3.3-web.wasm
LEVEL=4
time: 01.5s, size: 41MLEVEL=6
time: 03.8s, size: 37MLEVEL=8
time: 10.8s, size: 36MLEVEL=9
time: 43.0s, size: 35MLEVEL=10
time: 3m, size: 33MLEVEL=11
time: 9m, size: 30MWe also looked at using the WebAssembly Binaryen
wasm-opt
utility as an optimization step but decided to omit as the step only reduced a small % of size while adding several minutes to the build.