IndexedDB is a low-level API for client-side storage of significant amounts of structured data, including files/blobs. This API uses indexes to enable high-performance searches of this data. While Web Storage is useful for storing smaller amounts of data, it is less useful for storing larger amounts of structured data. IndexedDB provides a solution. This is the main landing page for MDN's IndexedDB coverage — here we provide links to the full API reference and usage guides, browser support details, and some explanation of key concepts.
Note: IndexedDB API is powerful, but may seem too complicated for simple cases. If you'd prefer a simple API, try libraries such as localForage, dexie.js, ZangoDB, PouchDB, and JsStore that make IndexedDB more programmer-friendly.
IndexedDB is a transactional database system, like an SQL-based RDBMS. However, unlike SQL-based RDBMSes, which use fixed-column tables, IndexedDB is a JavaScript-based object-oriented database. IndexedDB lets you store and retrieve objects that are indexed with a key; any objects supported by the structured clone algorithm can be stored. You need to specify the database schema, open a connection to your database, and then retrieve and update data within a series of transactions.
Note: Like most web storage solutions, IndexedDB follows a same-origin policy. So while you can access stored data within a domain, you cannot access data across different domains.
Operations performed using IndexedDB are done asynchronously, so as not to block applications. IndexedDB originally included both synchronous and asynchronous APIs. The synchronous API was intended for use only with Web Workers but was removed from the spec because it was unclear whether it was needed. However, the synchronous API may be reintroduced if there is enough demand from web developers.
There are a number of web technologies that store data of one kind or another on the client side (i.e. on your local disk). IndexedDB is the most commonly talked about one. The process by which the browser works out how much space to allocate to web data storage and what to delete when that limit is reached is not simple, and differs between browsers. Browser storage limits and eviction criteria attempts to explain how this works, at least in the case of Firefox.
To get access to a database, call open()
on the indexedDB
attribute of a window object. This method returns an IDBRequest
object; asynchronous operations communicate to the calling application by firing events on IDBRequest
objects.
IDBEnvironment
window
and worker
objects. This interface isn't part of the 2.0 specification.IDBFactory
indexedDB
and is therefore the entry point for the API.IDBOpenDBRequest
IDBDatabase
IDBTransaction
IDBRequest
IDBObjectStore
IDBIndex
IDBObjectStore
.IDBCursor
IDBCursorWithValue
IDBKeyRange
IDBLocaleAwareKeyRange
createIndex()
's optionalParameters.). This interface isn't part of the 2.0 specification.This specification fires events with the following custom interface:
IDBVersionChangeEvent
IDBVersionChangeEvent
interface indicates that the version of the database has changed, as the result of an IDBOpenDBRequest.onupgradeneeded
event handler function.An early version of the specification also defined these now removed interfaces. They are still documented in case you need to update previously written code:
IDBVersionChangeRequest
IDBFactory.open
without also calling IDBDatabase.setVersion
), and the interface IDBOpenDBRequest
now has the functionality of the removed IDBVersionChangeRequest
.IDBDatabaseException
IDBTransactionSync
IDBTransaction
.IDBObjectStoreSync
IDBObjectStore
.IDBIndexSync
IDBIndex
.IDBFactorySync
IDBFactory
.IDBEnvironmentSync
IDBEnvironment
.IDBDatabaseSync
IDBDatabase
.IDBCursorSync
IDBCursor
.Specification | Status | Comment |
---|---|---|
Indexed Database API | Recommendation | Initial definition |
Indexed Database API 2.0 | Recommendation |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | 23webkit 24 (unprefixed) 38 (prefixes deprecated) 57 (prefixes removed) | (Yes) |
10.0 (10.0) moz 16.0 (16.0) | 10 | 15 | 7.1, partial |
Available in workers |
(Yes) (unprefixed) 38 (prefixes deprecated) 57 (prefixes removed) | (Yes) | 37.0 (37.0)[1] | (Yes) | (Yes) | 10 |
Available in privacy mode[3] | (Yes) | No support | No support | No support | No support | No support |
IDBLocaleAwareKeyRange | No support | No support | 43.0 (43.0)[2] | No support | No support | No support |
Indexed Database 2.0 | 58 | ? | ? | ? | 45 | 10.1 |
Feature | Android Webview | Chrome for Android | Edge | Firefox Mobile (Gecko) | Firefox OS | IE/Edge Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|---|
Basic support |
(Yes) (unprefixed) 38 (prefixes deprecated) 57 (prefixes removed) |
(Yes) (unprefixed) 38 (prefixes deprecated) 57 (prefixes removed) | (Yes) | 22.0 (22.0) | 1.0.1 | 10 | 22 | 8, partial 10 |
Available in workers |
(Yes) (unprefixed) 38 (prefixes deprecated) 57 (prefixes removed) |
(Yes) (unprefixed) 38 (prefixes deprecated) 57 (prefixes removed) | (Yes) | 37.0 (37.0)[1] | (Yes) | (Yes) | (Yes) | 10 |
Available in privacy mode[3] | No support | No support | No support | No support | No support | No support | ? | ? |
IDBLocaleAwareKeyRange | No support | No support | No support | 43.0 (43.0)[2] | 2.5[2] | No support | No support | No support |
Indexed Database 2.0 | 58 | 58 | ? | ? | ? | 10.1 | 45 | ? |
IDBCursorWithValue
is not available in workers until Gecko 42.0 (Firefox 42.0 / Thunderbird 42.0 / SeaMonkey 2.39).
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API