Use compressed WASM for even smaller webroot size
All checks were successful
check / stable / fmt (push) Successful in 21s
check / nightly / doc (push) Successful in 2m24s
check / ubuntu / stable / features (push) Successful in 2m27s
check / ubuntu / 1.87.0 (push) Successful in 2m18s

This commit is contained in:
2025-11-15 14:42:03 -06:00
parent 46892ec32c
commit 6329d000f5
2 changed files with 12 additions and 7 deletions

View File

@@ -17,19 +17,19 @@ SRCS := $(wildcard $(SRC_DIR)/**)
# "Standalone" version
# (i.e., it includes an index.html so it can be placed on a server as-is)
web-standalone: out/boids.js out/boids_bg.wasm out/index.html
web-standalone: out/boids.js out/boids_bg.wasm.gz out/index.html
# "Bundle-able" version. The host site must provide it's own HTML page.
web: out/boids.js out/boids_bg.wasm out/boids.html
web: out/boids.js out/boids_bg.wasm.gz out/boids.html
tarball: boids_web_root.tar
tarball_standalone: boids_web_root_standalone.tar
boids_web_root.tar: out/boids.js out/boids_bg.wasm out/boids.html
boids_web_root.tar: out/boids.js out/boids_bg.wasm.gz out/boids.html
tar -caf $@ $^
boids_web_root_standalone.tar: out/boids.js out/boids_bg.wasm out/index.html
boids_web_root_standalone.tar: out/boids.js out/boids_bg.wasm.gz out/index.html
tar -caf $@ $^
target/$(CARGO_TARGET)/$(CARGO_PROFILE)/another-boids-in-rust.wasm: $(SRCS) Cargo.lock Cargo.toml
@@ -40,8 +40,9 @@ out:
# Both the JS and WASM files are generated by the wasm-bindgen call, so both
# get to be on the target half of this recipe.
out/boids.js out/boids_bg.wasm &: target/$(CARGO_TARGET)/$(CARGO_PROFILE)/another-boids-in-rust.wasm | out
out/boids.js out/boids_bg.wasm.gz &: target/$(CARGO_TARGET)/$(CARGO_PROFILE)/another-boids-in-rust.wasm | out
wasm-bindgen --no-typescript --target web --out-dir ./out/ --out-name boids target/$(CARGO_TARGET)/$(CARGO_PROFILE)/another-boids-in-rust.wasm
gzip -9 -f out/boids_bg.wasm
# Copies the index page to the output
out/index.html: www/index.html
@@ -68,5 +69,5 @@ full-clean: clean
install: web
install -dm0755 $(DESTDIR)
install -m0644 out/boids.js $(DESTDIR)/
install -m0644 out/boids_bg.wasm $(DESTDIR)/
install -m0644 out/boids_bg.wasm.gz $(DESTDIR)/
install -m0644 out/boids.html $(DESTDIR)/

View File

@@ -112,7 +112,11 @@
<script type="module">
import init from './boids.js'
init().catch((error) => {
let compressed = await fetch("./boids_bg.wasm.gz")
let wasm_stream = compressed.body.pipeThrough(new DecompressionStream("gzip"))
let blob = await new Response(wasm_stream).blob();
init(await blob.arrayBuffer()).catch((error) => {
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
throw error;
}