IndexedDB
In one line
IndexedDB is a browser API for storing large volumes of structured, queryable data persistently on the client.
In simple words
IndexedDB is a transactional, NoSQL database built into the browser. Unlike localStorage (which stores small strings), IndexedDB can store megabytes or gigabytes of structured data: objects, files, blobs, arrays. Data persists across sessions and survives page reloads.
You create named object stores (like tables), add indexes for fast lookups, and read/write through transactions. The API is asynchronous and callback-based (though promises wrappers like idb make it ergonomic). Keys can be auto-incremented or supplied, and you can query by key range or index.
Use IndexedDB for offline-first apps (caching API responses, storing user-generated content), large client-side datasets, and progressive web apps. It is more complex than localStorage but vastly more powerful for real client-side storage.
Example
// Open a database and store a record
const req = indexedDB.open("MyDB", 1);
req.onupgradeneeded = (e) => {
const db = e.target.result;
if (!db.objectStoreNames.contains("users")) {
db.createObjectStore("users", { keyPath: "id" });
}
};
req.onsuccess = (e) => {
const db = e.target.result;
const tx = db.transaction("users", "readwrite");
tx.objectStore("users").add({ id: 1, name: "Ada" });
};onupgradeneeded creates the object store. A readwrite transaction adds a record. Data persists across reloads.
Related terms
Related Resources
Related Lessons
- Client Storage
Learn IndexedDB and localStorage.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.