Guide · Browser storage

OPFS vs IndexedDB: a benchmark you can run yourself

For heavy lifting in the browser, such as offline data, large datasets or files, you have two real options: IndexedDB and the Origin Private File System (OPFS). Most published benchmarks come from vendors. This one runs in your browser, on your device, right on this page.

Two very different tools

IndexedDBOPFS
Data modelObject store: records with keys and indexesFiles and folders, private to your site
Best forStructured data you queryLarge files and binary data
QueryingKeys, indexes, rangesNone. You read bytes.
Fastest APIBatched writes in one transactionSync access handle (worker only)
In Web WorkersYesYes, required for sync access
QuotaShared per-origin quota, usually much larger than localStorage

Coming from localStorage? Start with when localStorage is enough.

Run the benchmark

It generates dummy records, writes and reads them with each API, and deletes everything afterwards. Nothing leaves your device.

Results appear here. Try it in a few different browsers.

It's a fair-but-simple test: IndexedDB stores the data as individual records (how you'd use it), while OPFS stores the same data as one file (how you'd use it). Treat the numbers as a guide for your own case, not a universal ranking.

Heavy lifting: move it to a Web Worker

Whichever storage you pick, large reads, writes and processing belong off the main thread, so scrolling and typing stay smooth. A minimal IndexedDB setup inside a worker, with no library:

JavaScript · storage.worker.js
const dbReady = new Promise((resolve, reject) => {
  const req = indexedDB.open("app", 1);
  req.onupgradeneeded = () => req.result.createObjectStore("items", { keyPath: "id" });
  req.onsuccess = () => resolve(req.result);
  req.onerror = () => reject(req.error);
});

onmessage = async ({ data: { type, items } }) => {
  const db = await dbReady;
  if (type === "save") {
    const tx = db.transaction("items", "readwrite");
    const store = tx.objectStore("items");
    for (const item of items) store.put(item); // one transaction, many writes
    tx.oncomplete = () => postMessage({ type: "saved", count: items.length });
  }
};
JavaScript · main thread
const worker = new Worker("/storage.worker.js");
worker.onmessage = ({ data }) => console.log(`saved ${data.count} items`);
worker.postMessage({ type: "save", items: bigArrayOfRecords });

Practical rules

  • Batch writes into one transaction. Many tiny transactions are the most common IndexedDB slowdown.
  • Split big data into chunks instead of one giant record, so updates only rewrite what changed.
  • Prefer ArrayBuffers for binary data in IndexedDB. Blob storage has had browser-specific problems, notably on older Safari versions.
  • Ask for persistence with navigator.storage.persist() when losing the data would hurt.
  • Test in every target browser. Storage performance differs more between browsers than almost anything else.

FAQ

Is OPFS faster than IndexedDB?

Often, for large binary or file-like data, especially through a Web Worker with a synchronous access handle. But results vary a lot by browser, device and access pattern. Run the benchmark on this page in the browsers your users actually use.

When should I use IndexedDB instead of OPFS?

Use IndexedDB for structured records you need to look up, filter or index, such as offline app data, caches and queues. Use OPFS for files and large binary blobs you read and write as a whole or in chunks, like media, exports, or a WebAssembly database file.

Do OPFS and IndexedDB work in Web Workers?

Yes. Both are available in workers, which is where heavy work belongs so the UI stays responsive. OPFS's fastest API, createSyncAccessHandle, is only available inside dedicated Web Workers.

How much can I store in IndexedDB or OPFS?

Both share the same per-origin quota, which depends on the browser and free disk space and is usually far larger than localStorage. Check the current estimate with navigator.storage.estimate(), and request persistence with navigator.storage.persist() if the data shouldn't be evicted.

Does this benchmark send my data anywhere?

No. It generates dummy data, writes and reads it locally in your browser, then deletes it. Nothing leaves your device.