Repository navigation
web gallery: cache each demo's wasm, data and glue by content hash - #1363
Merged
Merged
Conversation
… content hash
GitHub Pages serves every file with max-age=600 and an ETag made from the file's time, and deploy
pages rewrites every file on each push to master, so after any deploy the browser revalidated and
downloaded arigl.wasm (59 MB, 17 MB on the wire), arigl.data and arigl.js again, changed or not.
The page also fetched the wasm with cache: 'no-cache'.
build-pages.py now bakes each template page's large files into it as ASSETS ({wasm, data, js},
each name, the first 16 hex digits of its SHA-256 and size). demo.html.in keeps them in Cache
Storage keyed by name + hash: a hit is used with no request at all; a miss is downloaded (one
progress line), kept under the hash of the bytes that came, and that asset's other versions are
deleted. The .data goes to Emscripten through Module.getPreloadedPackage and the glue runs from a
blob URL (Module.mainScriptUrlOrBlob keeps a threaded build's workers on the real URL). A copy of
the page older than the deploy, whose download hashes differently, reloads itself once per page
version. Without Cache Storage (insecure context, some private windows, storage errors) or with
?nocache the page loads as before.
deploy-pages.yml: a push touching only docs/, top-level notes (THIRD_PARTY_NOTICES.md excepted,
it ships in the gallery), .github/ other than this workflow, or bindings/ no longer redeploys.
Every deploy since 2026-11-18T23:13 fails at link with libfreetype.a(ftbase.c.o): undefined symbol: __wasm_longjmp (run 44437115573): cy-pca/cvcpkg#624 (JX1) republished wasm packages built with -fwasm-exceptions, and libcvc still builds with JS exceptions until JX2. #1360 adds .github/scripts/pin-wasm-pre-jx1.sh and calls it in ci.yml; this calls it at the end of the deploy's install step, after every wasm install, and lets a change to the script redeploy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The web gallery (https://transfix.github.io/libcvc/) downloaded its large files again on nearly every load.
Cause
Cache-Control: max-age=600and an ETag made from the file's timestamp (for example"6afe3a7c-2e28b2"). We can't change either.deploy pagesruns on every push to master, plus a nightly cron, and each deploy rewrites every file. So every ETag changes even when the bytes don't, and a revalidation downloads the whole file. About 20 pushes landed on 2026-11-18 alone.demo.html.infetched<demo>.wasm?v=<hash>withcache: 'no-cache', which revalidates on every load.arigl.wasmis 59 MB (17 MB gzipped).arigl.data(about 3 MB) andarigl.js(0.4 MB) went through the same HTTP cache: the.datawas fetched by Emscripten's loader with no content hash in its URL.Fix
Content-addressed caching in the page (
examples/web/build-pages.py,examples/web/templates/demo.html.in):ASSETS = {wasm, data, js}, each with{name, hash, size}.hashis the first 16 hex digits of the file's SHA-256..datais listed only when the demo has one.{{ASSET_V}}still renders, with the same value as before, for downstream templates that use it.cvcgl-demo-assets), keyed by<name>?v=<hash>..datagoes to Emscripten throughModule.getPreloadedPackage(name, size), which returns an ArrayBuffer, so its loader doesn't fetch it.Module.mainScriptUrlOrBlobpoints a threaded build's workers at the real URL.caches.openrejecting), or with?nocachefor debugging, the page loads as before: the wasm withno-cache, the glue by<demo>.js?v=<hash>, and the.databy Emscripten itself. A failedput(for example a quota error) costs only the caching.Fewer pointless deploys (
.github/workflows/deploy-pages.yml): the push trigger now has apathsfilter. It leaves outdocs/**, top-level*.md(but keepsTHIRD_PARTY_NOTICES.md, which ships in the gallery),.github/**(but keeps this workflow and the pin script it runs), andbindings/**(the gallery is built withCVC_BUILD_PYCVCoff). Other.mdfiles still trigger a deploy:arigl.datapacksexamples/dataincluding its README, and arigl's wasm embedssrc/cvcGL/fontsincludingREADME.md. Thescheduleandworkflow_dispatchtriggers are unchanged. Over 2026-11-11..18 the filter would have skipped 17 of 185 master pushes. Most pushes touch the library, so the cache does most of the work here.Pre-JX1 wasm pin in the deploy (
.github/workflows/deploy-pages.yml, second commit): every deploy since 2026-11-18T23:13 has failed at link withlibfreetype.a(ftbase.c.o): undefined symbol: __wasm_longjmp(run 44437115573). The cause is cy-pca/cvcpkg#624 (JX1), which republished wasm packages built with-fwasm-exceptions. #1360 adds.github/scripts/pin-wasm-pre-jx1.shand calls it in ci.yml only. This PR calls it at the end of the deploy's "Install fresh wasm dep closure + scene bundles" step, asbash .github/scripts/pin-wasm-pre-jx1.sh "$CVC_WASM_DEPS" wasm. It runs after every wasm install, so none of those installs can move a pinned package back. The paths filter keeps that script in, so a change to it redeploys. I checked that the pinned versions exist on cvcpkg.org as wasm/wasm32 static release bundles (cvcpkg search).Depends on #1360: the script exists only on that branch. Once #1360 lands, origin/master gets merged into this branch (a merge commit, not a rebase). Don't merge this PR before that.
Expected effect
An unchanged file is never downloaded again. A changed one is downloaded once per change. A redeploy of identical bytes, such as a docs-only push that still deploys or the nightly cron with no source change, costs a page revalidation and nothing more.
arigl.wasmlinks most of the library, so a push that changes code reaching arigl still changes its hash, and that costs one download of the wasm only. The.dataand the glue change far less often.Tested
bin/(arigl with.wasm/.data/.js, lsystem_forest without.data,ariwith its own page) using the realdemos.jsonand gallery assets:ASSET_Vequals the old script's value;max-age=600, ETag from mtime and size), with valid wasm modules and a fake glue that reports how it got its files:.dataarrived throughgetPreloadedPackageas an ArrayBuffer, the glue ran from a blob URL, and the wasm instantiated.?nocache: same requests as master's page..data: works.putrejecting,matchthrowing,caches.openrejecting: each falls back as intended.Not verified
arigl.js(getPreloadedPackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE), the ArrayBuffer check,scriptDirectoryfromnew URL('.', currentScript.src)), but no wasm was built here.mainScriptUrlOrBlob.ari,ari_tvisionviaari-web.js, andarigl_term) are unchanged and still revalidate on each load.ari-web.jsruns underscript-src 'self', which rules out the blob-URL glue, so they need their own change.