Cross-Origin Storage Could Make Local AI on the Web Practical

November 19, 2026 | 19 minutes

Running small language models directly in the browser has become surprisingly practical. WebGPU gives us hardware acceleration, libraries like Transformers.js make model execution accessible from JavaScript, and quantization has made models small enough to run on everyday hardware. But there's an architectural problem that becomes obvious as local AI proliferates: every application needs its own copy of the model.

Imagine using three separate tools:

  • A document editor with local summarization.
  • A browser-based coding assistant.
  • A small AI-powered accessibility tool.

All three could use the same model, with identical weights, tokenizer files, and runtime dependencies. But because they're hosted on different sites, each application typically downloads and caches its own copy of the model. For a 500 MB model, that's potentially 1.5 GB of downloads across three applications, even though the underlying bytes are identical.

Google's recently announced Cross-Origin Storage proposal attempts to address this by introducing a content-addressed cache that applications can share across origins, potentially changing how we think about distributing AI capabilities on the web.

Why Can't Browsers Already Share These Models?

Browsers have supported caching for a long time via the HTTP cache, Cache Storage API, IndexedDB, and Origin Private File System (OPFS). So why do we need another storage mechanism? The reason is that these existing mechanisms isolate data for security and privacy reasons.

Consider two applications loading the same model from the same CDN. With a partitioned HTTP cache, each site looks in its own partition:

Even when the model URL is identical, the browser's HTTP cache partitioning prevents the second application from reusing the first application's cached response. This is intentional because cross-site cache reuse has historically enabled tracking attacks.

The idea is that if a website can determine whether a specific resource is already cached, it may be able to infer which other websites you've visited. Consider a historical, unpartitioned HTTP cache. Instead of a widely shared model, imagine a logo used only by a particular site:

The attacker doesn't need to read the browser's history directly to infer what other sites you've visited; the loading time can reveal a clue. It's an inference, not proof: timing is noisy, and another page could also have loaded the image. Cache partitioning protects against those attacks by preventing unrelated sites from observing each other's cache state at the expense of duplicate storage. For small JavaScript files, duplicate storage costs are fairly minor, but for models measuring hundreds of megabytes or several gigabytes, it becomes much more significant.

The Idea Behind Cross-Origin Storage

Cross-Origin Storage (COS) takes a different approach to identifying cached resources. Instead of identifying a file by the URL it was downloaded from, COS identifies it by a cryptographic hash of its contents.

Conceptually:

Two files with identical bytes have the same SHA-256 hash, regardless of where they were downloaded, giving us a way to separate what a resource is from where it came from.

The current API proposal makes this accessible through navigator.crossOriginStorage:

1const hash = {
2  algorithm: "SHA-256",
3  value: MODEL_SHA256
4};
5
6const handle =
7  await navigator.crossOriginStorage.getFileHandle(hash);
8
9const file = await handle.getFile();

With this architecture, the application has to already know the hash it wants. There's no directory of shared resources, so it can't be used as a general-purpose API for discovering what another website has downloaded.

Knowing the hash isn't permission to read the file

Under the current proposal, the hash identifies the bytes you want, but it doesn't authorize access. The current COS draft separates the two decisions:

  • Sharing is explicit. Storing a model doesn't automatically expose it to unrelated sites. For example, a model stored by editor.example isn't automatically readable by assistant.example, even if both know its hash. Explicit recipients must also be authorized by the Cross-Origin-Storage-Allow-Origin header on the HTTP response that served the page storing the model.
  • Global sharing has another gate. Requesting origins: "*" isn't enough. Readers relying on that permission also need the file's hash to appear on the proposed Public Hash List: a list intended for identical resources used by many independent sites. This limits what a cache hit reveals: a common model could have come from thousands of websites, while a unique file could identify a particular visit or user. Note: being on the list makes a resource eligible for global reuse; it doesn't mean the file is already cached on the user's device.
  • Cache misses can protect privacy. getFileHandle() can reject with NotFoundError even when the bytes exist, because the caller isn't allowed to learn they're there. The application should fall back to a normal download in this case rather than interpreting the error as evidence about browsing history.

Remember that these are proposed protections with experimental support, not guarantees of a shipped browser implementation, so their details may change as the API develops.

Building a Small Cross-Origin Model Experiment

To test the storage path, I ran two local applications on different HTTPS sites: https://localhost:14517 and https://127.0.0.1:14518. Both requested the same model URL from a third local server and explicitly authorized each other to reuse the stored bytes. Using different hostnames matters here: two HTTP localhost ports would give us different origins, but they'd still be on the same site.

For this first experiment, I used a generated ONNX model that multiplies a vector by 2. The model file is 4,194,438 bytes, or just over 4 MiB, and a second revision changes the multiplier to 3 while keeping the same file size. Both perform real inference through ONNX Runtime Web's WASM backend, but neither is a language or speech recognition model. That keeps the test small and gives us an exact expected result while exercising the streamed download, integrity check, and cross-origin reuse described below.

The Chrome team's Transformers.js integration already provides an experimental COS caching backend. The interesting part is how little application code needs to change.

1import {
2  env,
3  pipeline
4} from "@huggingface/transformers";
5
6// Experimental API: enable before loading a pipeline.
7env.experimental_useCrossOriginStorage = true;
8
9const transcriber = await pipeline(
10  "automatic-speech-recognition",
11  "Xenova/whisper-tiny.en",
12  {
13    device: "wasm"
14  }
15);
16
17const result = await transcriber(audioUrl);

The example attempts to resolve model assets through COS and falls back to conventional loading when necessary. It also uses the WASM backend, as does the measured ONNX demo. WebGPU is another option on supported devices, but keeping the backend consistent helps focus the experiment on caching rather than GPU performance differences.

The current proposal is not a broadly shipped native browser feature, so for now, testing requires the Cross-Origin Storage browser extension, which polyfills the proposed API. These results are useful for exploring behavior, but remember that they aren't a substitute for validating eventual browser implementations.

What Happens When a Resource Isn't Cached?

The cache hit is relatively straightforward. The more important path is what happens when storage doesn't contain a resource or when the browser decides not to reveal it. The current workflow should look like this:

Let's make that fallback explicit. The example below checks for COS before using it, falls back only for expected cache-access errors, and verifies downloads without creating a model-sized JavaScript buffer.

It uses hash-wasm for incremental SHA-256 hashing.

The network path streams the response through a hasher into a temporary file in the Origin Private File System (OPFS) that's only exposed to the model loader after the digest matches the trusted hash. This requires HTTPS (or a trustworthy local development origin), OPFS writable streams, and enough local storage; it doesn't require COS support.

1import { createSHA256 } from "hash-wasm";
2
3// Local types for the experimental API; these may change with the proposal.
4type COS = {
5  getFileHandle(
6    hash: { algorithm: string; value: string },
7    options?: { create: boolean; origins: string[] }
8  ): Promise<FileSystemFileHandle>;
9};
10
11function hasErrorName(error: unknown, names: string[]): boolean {
12  return error instanceof Error && names.includes(error.name);
13}
14
15async function withSharedAsset<T>(
16  url: string,
17  sha256: string,
18  consume: (file: File) => Promise<T>,
19  signal?: AbortSignal
20): Promise<T> {
21  if (!/^[0-9a-f]{64}$/.test(sha256)) {
22    throw new TypeError("Expected a lowercase SHA-256 hash from a trusted source");
23  }
24  signal?.throwIfAborted();
25
26  const hash = { algorithm: "SHA-256", value: sha256 };
27  const candidate = (navigator as Navigator & { crossOriginStorage?: COS })
28    .crossOriginStorage;
29  const cos = typeof candidate?.getFileHandle === "function" ? candidate : undefined;
30  const unavailable = ["NotAllowedError", "SecurityError", "NotSupportedError"];
31  let cachedFile: File | undefined;
32
33  if (cos) {
34    try {
35      const handle = await cos.getFileHandle(hash);
36      cachedFile = await handle.getFile();
37    } catch (error) {
38      if (!hasErrorName(error, ["NotFoundError", ...unavailable])) throw error;
39      // A miss or denied access is a reason to try the network.
40    }
41  }
42
43  signal?.throwIfAborted();
44  // Keep consumer errors outside the cache lookup's catch block.
45  if (cachedFile) return await consume(cachedFile);
46
47  if (typeof navigator.storage?.getDirectory !== "function") {
48    throw new Error("This streaming download requires OPFS support");
49  }
50
51  const root = await navigator.storage.getDirectory();
52  const name = `cos-download-${crypto.randomUUID()}`;
53  const temporary = await root.getFileHandle(name, { create: true });
54
55  try {
56    if (typeof temporary.createWritable !== "function") {
57      throw new Error("This browser does not support OPFS writable streams");
58    }
59
60    const hasher = await createSHA256();
61    hasher.init();
62    const response = await fetch(url, { signal });
63    if (!response.ok || !response.body) {
64      await response.body?.cancel();
65      throw new Error(`Asset download failed: HTTP ${response.status}`);
66    }
67
68    // If opening the file fails, stop the unused network response too.
69    let writable: FileSystemWritableFileStream;
70    try {
71      writable = await temporary.createWritable();
72    } catch (error) {
73      await response.body.cancel();
74      throw error;
75    }
76
77    await response.body
78      .pipeThrough(new TransformStream<Uint8Array, Uint8Array>({
79        transform(chunk, controller) {
80          hasher.update(chunk);
81          controller.enqueue(chunk);
82        }
83      }))
84      .pipeTo(writable, { signal });
85    // pipeTo closes the file on success and aborts it on stream failure.
86
87    if (hasher.digest("hex") !== sha256) {
88      throw new Error("Model asset failed integrity verification");
89    }
90    const file = await temporary.getFile();
91
92    if (cos) {
93      try {
94        const handle = await cos.getFileHandle(hash, {
95          create: true,
96          origins: ["https://localhost:14517", "https://127.0.0.1:14518"]
97        });
98        await file.stream().pipeTo(await handle.createWritable(), { signal });
99      } catch (error) {
100        if (!hasErrorName(error, ["QuotaExceededError", ...unavailable])) throw error;
101        console.warn("COS write skipped; using the verified temporary file", error);
102      }
103    }
104
105    signal?.throwIfAborted();
106    return await consume(file);
107  } finally {
108    // Remove only this invocation's file, even after a failed download or inference.
109    try {
110      await root.removeEntry(name);
111    } catch (error) {
112      // Don't replace the original download/consumer error with a cleanup error.
113      console.warn("Temporary file cleanup failed", error);
114    }
115  }
116}

The consume callback must finish reading the file before it resolves; the helper removes its temporary file afterward. For example, an application-specific loader can use an object URL while it initializes a model session:

1const session = await withSharedAsset(MODEL_URL, MODEL_SHA256, async (file) => {
2  const objectUrl = URL.createObjectURL(file);
3  try {
4    return await initializeModelFromUrl(objectUrl);
5  } finally {
6    URL.revokeObjectURL(objectUrl);
7  }
8});

MODEL_URL, MODEL_SHA256, and initializeModelFromUrl are supplied by your application. The initializer must finish consuming the URL before resolving.

The example shows how to load one verified asset. It's not a drop-in replacement for the Transformers.js pipeline, which may need several model and tokenizer files. Get each expected hash from trusted release metadata, not from the same untrusted download you're trying to verify.

Expected COS misses and access restrictions trigger the download path, and a full COS cache doesn't prevent using a verified temporary file. Network failures, integrity mismatches, cancellation, and unexpected API errors still reach the caller. OPFS quota or permission failures also reach the caller: the UI should explain that local loading couldn't complete. The temporary file avoids a full-file hashing buffer, but still uses disk space, and the inference runtime can still allocate substantial memory. A tab crash can leave temporary files behind, so a complete application also needs a cleanup policy that accounts for downloads active in other tabs.

This example uses an explicit origin allowlist for our two demo sites instead of requesting global sharing with origins: "*". Either application can store the model and authorize the other to reuse it. The JavaScript allowlist isn't sufficient on its own, though. Configure both demo servers to include this header on the HTTP response that serves the application page:

1Cross-Origin-Storage-Allow-Origin: https://localhost:14517, https://127.0.0.1:14518

For this page-based JavaScript API, the header belongs on the application's HTML response, not merely the model download response. In the current draft, requested recipients missing from that header are dropped from the sharing grant, even though the file can still be stored.

Explicitly authorized readers don't depend on Public Hash List membership, so this setup lets us test reuse without assuming the chosen model is on that list. It doesn't guarantee a cache hit: the file may be absent or evicted, and other browser access controls still apply, making the network fallback necessary.

What Happened When I Ran the Experiment?

I repeated the experiment five times, starting each round with a fresh browser profile and extension cache. The runs used Chrome for Testing 159.0.8154.6 on an Apple M3 Max, the COS extension at version 0.1.40, and ONNX Runtime Web 1.31.1 with a single WASM thread. Each round followed the same sequence: load v1 in App A, reuse it in App B, bypass COS in App B, try v2, delete v1 from the extension's cache, and load v1 again. Finally, App A tried reusing the copy that App B had just stored.

The table shows model response bytes consumed by the application and median timings across those five rounds. Asset-loading time includes the COS lookup or the download, hashing, and storage work before handing the file to the inference runtime. Runtime initialization is measured separately from inference.

ScenarioModel bytes downloadedMedian asset loadingMedian inference
App A, fresh profile, v14,194,4381,191 ms6 ms
App B, reuse v1040 ms5.4 ms
App B, COS disabled, v14,194,438864 ms2.6 ms
App B, first load of v24,194,438889 ms2.2 ms
App B, v1 explicitly deleted from COS4,194,438890 ms2.2 ms
App A, reuse v1 now stored by B019 ms2.2 ms

The clearest result is the download count. In every round, App B's first run reused the exact model bytes stored by App A without making another model request. The model server's request log confirmed that, and inspecting the extension's cache after those two runs showed one model entry. Disabling COS caused App B to download all 4,194,438 bytes again. Changing the weights in v2 produced a new hash and another download, despite the file having the same size as v1. All runs produced the expected inference result: an input of 3 returned 6 for v1 and 9 for v2.

Deleting v1 from the extension's cache also caused the next request to download and store it again. App A could then reuse that new entry without downloading the model. This tests recovery from deliberate cache removal, but I didn't test natural browser eviction. The demo also removed its temporary OPFS download file after each run. Seeing one extension cache entry doesn't measure the browser's total disk footprint or prove that its internal buffers and runtime memory are deduplicated.

What the Timings Do and Don't Tell Us

The cache-hit path was faster in this setup, but these numbers aren't a production speed benchmark. The local server deliberately waits 12 ms after each 64 KiB chunk to make download progress and cancellation visible. Both the server and browser disable ordinary HTTP caching for model downloads, and later cases in each round benefit from an already-initialized runtime. That makes the timings useful for inspecting this demo's behavior, but not for predicting how much faster Whisper or a larger model would load over a real network.

Even with a cache hit, App B still spent a median of 112 ms initializing its own runtime before its first inference. This shows that COS avoided the duplicate model download, but it didn't eliminate initialization or share an inference session. The byte counts also exclude JavaScript, WASM runtime files, HTTP overhead, and other browser traffic. A fast load alone wouldn't establish reuse, which is why I checked the COS result and model server requests as well.

I ran the six scenarios in disposable browser profiles, using local test certificates with certificate-error handling relaxed only in those profiles and deleting cache entries only inside those isolated profiles. These results show that the extension can reuse a verified model across the two authorized sites, but they don't validate native-browser behavior, the proposed Public Hash List, or cross-site privacy protections.

The Hash Becomes Part of Your Dependency Management

One consequence of content-addressed storage is that even small changes to a file matter. Two models with the same architecture aren't necessarily interchangeable cached resources because different quantization settings and model revisions produce different files. Even repackaging an otherwise equivalent model can change its hash:

model-q4.onnx   → SHA-256: abc...
model-q8.onnx   → SHA-256: def...
model-v2.onnx   → SHA-256: ghi...

COS can't treat those assets as identical just because they represent the same model, so libraries and model publishers need stable, verifiable resource identifiers for shared storage to work well. If model hashes become an integral piece of how we share models, we may eventually care as much about the exact hash of a model artifact as we currently care about the version of an npm dependency.

What Cross-Origin Storage Doesn't Solve

While COS could reduce duplicate downloads, it doesn't make the models themselves smaller. The first application still needs to download the model unless the user already has a copy that the application is permitted to access. It also doesn't share inference sessions, so each application still needs to initialize its own runtime and manage its own execution state. Memory limits, GPU availability, inference latency, and model quality will continue to affect how practical local AI is for a particular application.

Multiple applications can also compete for the same hardware. Sharing the stored model file doesn't mean they share a running model instance or its memory, so opening several AI-powered tabs could still increase memory usage and slow inference. COS doesn't require those tabs to take turns, but it also doesn't coordinate their workloads or guarantee that the device can run them efficiently at the same time.

Cache availability is another limitation to keep in mind. Browsers can evict resources, restrict access, or return a cache miss for privacy reasons, so applications still need a way to load models when shared storage isn't available. And because COS is an early proposal, the API and its privacy controls may change significantly before native browser support arrives. For now, I'd treat it as an optimization that an application can benefit from when available, while making sure the application can still function without it.

Why I Think This Matters

For me, the interesting part of this proposal is how it could change the way we distribute models on the web. Today, each AI-powered website effectively takes responsibility for distributing its own model dependencies to every user. With content-addressed, shared storage, some of that responsibility could move toward the browser, allowing applications to reuse model artifacts.

That wouldn't make the browser an AI runtime by itself, but it would remove one of the more wasteful parts of building a collection of local AI applications. As browser-based AI becomes more common, sharing identical model bytes seems like a much better direction than downloading another copy every time someone opens a new tool. It also raises a question I'd like to explore next: what else would a browser-native AI runtime need beyond that shared storage layer?

References

Related Posts