Experimenting with the Proposed Cross-Origin Storage API in Transformers.js
Hugging Face
The Cross-Origin Storage (COS) API proposal aims to solve redundant downloads and caching of shared AI model and runtime resources across different web origins. Transformers.js currently suffers from duplicate storage of model weights and Wasm files due to browser cache isolation. COS identifies files by cryptographic hash rather than URL, enabling cross-origin sharing with integrity and access control.
Transformers.js allows web developers to run AI models in the browser via task-specific pipelines. However, popular models like Xenova/whisper-tiny.en are downloaded and cached separately per origin, leading to duplicate storage (e.g., 177 MB for a simple ASR example). Even Wasm runtime files like ort-wasm-simd-threaded.asyncify.wasm from ONNX Runtime are cached redundantly across origins, despite identical content. This is due to browser cache isolation using Network Isolation Keys based on top-level and current-frame sites. The proposed Cross-Origin Storage (COS) API introduces `navigator.crossOriginStorage` that stores files identified by a cryptographic hash (e.g., SHA-256). Apps can request a file handle by hash; if present, they read directly; if not, they download and store it with options for visibility: `origins: '*'` for global sharing, a list of origins for restricted sharing, or same-site only. The browser verifies the hash on write for integrity, and visibility can only be upgraded, not downgraded, to prevent malicious narrowing. COS is an early-stage proposal not yet natively implemented, but can be tested via a browser extension.
- Сокращения
- ASR = Automatic Speech Recognition — автоматическое распознавание речи
- CDN = Content Delivery Network — сеть доставки контента
- COS = Cross-Origin Storage — кросс-доменное хранилище
- Wasm = WebAssembly — веб-ассемблер
- OPFS = Origin Private File System — приватная файловая система источника
Source: Hugging Face blog —
original
