Speed up cold boot: build-time gzip_static, HF Hub CDN asset routing, and parallel prefetch
Summary
Cold loads of the Space currently transfer ~32 MB uncompressed through the single container proxy in a multi-stage sequential waterfall. This PR speeds up cold boot across three layers while keeping everything strictly inside the Space and Hugging Face infrastructure (no external CDNs):
Build-time
gzip -9pre-compression +gzip_static on;(Dockerfile)nginxinc/nginx-unprivileged:alpineonly compressestext/htmlby default, sending all.wasm,.js,.glb,.stl,.json, and.xmlfiles uncompressed. Pre-compressing assets duringdocker buildand enablinggzip_static on;reduces transfer sizes with zero runtime CPU cost on the container:mujoco.wasm:10.12 MB -> 2.52 MB(-75%)ort-wasm-simd-threaded.wasm:13.48 MB -> 3.50 MB(-74%)- JS chunks (
App.js,index.js,mujoco.js,ort.js):1.55 MB -> 0.45 MB(-71%) microduck.glb:1.28 MB -> 0.80 MB(-37%)- Bundle total:
25.15 MB -> 6.48 MB(18.67 MB saved on cold load).
Route public static assets through Hugging Face Hub CDN (
app/src/game/signed.js)
When running on the public production host (pollen-robotics-microduck-simulator.hf.spacewithout?__sign=), relative./robot/,./policies/, and./assets/paths resolve through the Space repo's own Hub CDN endpoint (/resolve/main/app/public/...->cdn.hf.co, which includes CORS headers on both the 302 redirect and edge response). This offloads static asset fetches from the single container replica (~4.6x higher throughput in benchmarks). Local dev (localhost),/play/, forked Spaces, private Spaces (?__sign=), and?cdn=0retain same-origin resolution.Collapse the serial boot waterfall (
app/src/game/game.js,app/src/game/duck.js)- Prefetch
loadGlbGeometries()(microduck.glb) and the 7 initial ONNX policy buffers at the start ofboot()in parallel with@mujoco/mujocoandonnxruntime-web/wasminstead of waiting formujoco.wasmcompilation andMjVFSsetup to finish first. - Deduplicate concurrent
loadKinematics()fetches betweenMenuDuckandboot(). - Added unit tests in
app/test/signed.test.js(12/12passing).
- Prefetch