trunk
trunk copied to clipboard
feat: Add compression support for wasm binary
This is an attempt to add compression support for wasm binary.
- Add
data-compression-algorithmanddata-compression-levelattributes. - Enable gzip compression by default on release build, can be disabled by set
data-compression-level="0". - Use DecompressionStream API to decompress at runtime.
Thanks for the PR. I guess this could be a valuable addition. There are two things:
- I think it would make sense doing a quick check/proof on how much this would safe. Showing one or two examples.
- It looks like this is missing out on the
elsewhen using the more complex initializer. It also seems to repeat code from the initializer, which does something similar. Maybe it's time to collapse both, and have the "non initializer" version be a special (simpler) form of the initializer version?
Thanks for the PR. I guess this could be a valuable addition. There are two things:
- I think it would make sense doing a quick check/proof on how much this would safe. Showing one or two examples.
- It looks like this is missing out on the
elsewhen using the more complex initializer. It also seems to repeat code from the initializer, which does something similar. Maybe it's time to collapse both, and have the "non initializer" version be a special (simpler) form of the initializer version?
I've merged repeat code and add missing compression support for custom initializer. Here are the file size savings with compression enabled. All examples were built with the release profile. By default, gzip compression is enabled with the default compression level:
| Example | Raw | wasm-opt processed (opt-level='z') | Compressed |
|---|---|---|---|
| initializer | 35 KB | 23 KB | 11 KB |
| leptos | 137 KB | 93 KB | 36 KB |
| yew | 450 KB | 307 KB | 104 KB |
| My Blog (Leptos 0.8) | 1349 KB | 819 KB | 330 KB |
All examples save about 50% to 70% in size.