Repository navigation
v0.33.0
wasmcache: an update no longer re-downloads unchanged files (#49).
Before: when a newer build was deployed, the new service worker fetched every listed file again, then deleted the old cache. For go-slides that meant about 10.3 MiB (playground.wasm, gzipped) per returning visitor on every deploy, even when only a 30 KB script changed. Lazy files, such as the 3.2 MiB video worker, were lost too and downloaded again on next use. This was measured in headless Chrome.
Now: at install, the worker copies a file from this playground's previous cache when its size and SHA-256 match the new manifest, and downloads it otherwise. Lazy files stored by the old build are copied the same way, and are never fetched at install.
- Hash check: every copied file is hashed against the new manifest before it is stored. A tampered or truncated old entry is downloaded again instead of reused.
- Scope: only caches named
"<name>|"are read, so other playgrounds on the same origin are never touched. - Failure: any failure during the copy falls back to the network. If the install fails, the half-built cache is deleted and the old build keeps serving, so a new build never activates with a file missing.
- Tests: a new step in the test kit (worker.js changed) asserts that unchanged files are requested 0 times, that a lazy file is copied with 0 requests, and that a tampered old entry is fetched and hash-checked. Removing the hash check, or the reuse itself, each fail that step by assertion.
Follow-up filed as #50: a copied entry still carries the old entry's headers. Only its bytes are checked against the manifest; the headers should be built from the manifest instead. This opens no new attack: only same-origin script can write Cache Storage, and such script could already write the live cache.