source: hugging face blog: experimenting with the proposed cross-origin storage api in transformers.js

level: technical

transformers.js runs ai models in the browser but wastes bandwidth and disk space because caches are isolated by origin. even when two sites use the same model or webassembly runtime, the browser downloads and stores separate copies. for example, the whisper-tiny.en model and a shared onnx runtime wasm file are duplicated across origins, adding up to 177 mb of waste in a simple demo.

the cross-origin storage api proposal fixes this by identifying files by their sha-256 hash instead of their url. when an app requests a file, it checks a shared cache using the hash. if found, it gets the file directly. if not, it downloads and stores it with an origins option that controls visibility: '*' for public resources like ai models, a list for restricted sharing, or same-site only by default. the browser verifies the hash on write, ensuring integrity.

privacy is handled by limiting which files can be globally probed. the browser may hide a file's presence if it hasn't been seen across enough origins, so apps must always fall back to the network on error. transformers.js is already testing this api, which could make web ai apps faster and more efficient by eliminating redundant downloads of shared components.

why it matters: reduces bandwidth and storage for web ai apps by sharing cached model and runtime files across sites, speeding up load times and lowering costs.


source: hugging face blog: experimenting with the proposed cross-origin storage api in transformers.js