IndexedDB is an API for client-side storage of significant amounts of structured data and for high performance searches on this data using indexes. While DOM 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.
Key concepts and usage
IndexedDB is a transactional database system, which is initially confusing if you are only used to working with relational databases, but becomes clear soon enough. IndexedDB lets you store and retrieve objects that are indexed with a key. You need to specify the database schema, open a connection to your database, and then retrieve and update data within a series of transactions.
- Read more about the concepts behind IndexedDB.
- Learn to use IndexedDB asynchronously from first principles with our Using IndexedDB guide.
- Find developer recommendations for making web apps work offline at our Offline Apps page.
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.
Synchronous and asynchronous
IndexedDB includes both an asynchronous API and a synchronous API. The asynchronous API can be used in most cases, including WebWorkers, while the synchronous API is intended for use only with Web Workers and will be used more rarely.
Note: Currently, no major browser supports the synchronous API.
Storage limits
There isn't any limit on a single database item's size, however there may be a limit on each IndexedDB database's total size. This limit (and the way the user interface will assert it) may vary from one browser to another:
- Firefox has no limit on the IndexedDB database's size. The user interface will just ask permission for storing blobs bigger than 50 MB. This size quota can be customized through the
dom.indexedDB.warningQuotapreference (which is defined in http://mxr.mozilla.org/mozilla-central/source/modules/libpref/src/init/all.js). - Google Chrome: see https://developers.google.com/chrome...rage#temporary.
Asynchronous API
The asynchronous API methods return without blocking the calling thread. To get asynchronous 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.
Connecting to a database
-
IDBEnvironment -
Provides access to a client-side database. It is implemented by the
windowandworkerobjects. -
IDBFactory -
Provides access to a database. This is the interface implemented by the global object
indexedDBand is therefore the entry point for the API. -
IDBOpenDBRequest - Represents a request to open a database.
-
IDBDatabase - Represents a connection to a database. It's the only way to get a transaction on the database.
Accessing results of database requests
-
IDBRequest - Provides access to results of asynchronous requests to databases and database objects. It is what you get when you call an asynchronous method.
Retrieving and modifying data
-
IDBTransaction - Represents a transaction. You create a transaction on a database, specify the scope (such as which object stores you want to access), and determine the kind of access (read only or write) that you want.
-
IDBObjectStore - Represents an object store.
-
IDBIndex - Provides access to the metadata of an index.
-
IDBCursor - Iterates over object stores and indexes.
-
IDBCursorWithValue - Iterates over object stores and indexes and returns the cursor's current value.
-
IDBKeyRange - Defines a range of keys.
Deprecated interfaces
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 -
Represents a request to change the version of a database. The way to change the version of the database has since changed (by calling
IDBFactory.openwithout also callingIDBDatabase.setVersion), and the interfaceIDBOpenDBRequestnow has the functionality of the removedIDBVersionChangeRequest. -
IDBDatabaseException - Represents exception conditions that can be encountered while performing database operations.
Synchronous API
Important: This is a reminder that the synchronous version of IndexedDB is not yet implemented in any browser.
To get synchronous access to a database, call open() on the Unimplemented indexedDBSync attribute of a worker object. This returns an IDBDatabaseSync object, which enables you to create, open, and remove object stores and indexes, set the version of the database, and create transactions.
IDBCursorSynciterates over object stores and indexes.IDBDatabaseSyncrepresents a connection to a database. It's the only way to get a transaction on the database.IDBEnvironmentSyncprovides access to a client-side database. It is implemented by worker objects.IDBFactorySyncprovides access to a database.IDBIndexSyncprovides access to the metadata of an index.IDBObjectStoreSyncrepresents an object store.IDBTransactionSynccreates a transaction in the database.
Examples
- eLibri: A powerful library and eBook reader application, written by Marco Castelluccio, winner of the IndexedDB Mozilla DevDerby.
- To-do Notifications (view example live): The reference application for the examples in the reference docs: Not every snippet appears in this example, but every example uses the same data structure and syntax, and will make sense in the context of this application.
- Storing images and files in IndexedDB
- IndexedDB Examples
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| Asynchronous API |
11.0 webkit |
4.0 (2.0) moz 16.0 (16.0) |
10 | 17 | Not supported |
| Synchronous API (used with WebWorkers) |
Not supported | Not supported See bug 701634 |
Not supported | Not supported | Not supported |
| Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Asynchronous API | 4.4 | 6.0 (6.0) moz 16.0 (16.0) |
10 | 17 | Not supported |
Note: Some browsers don't yet support IndexedDB but do support WebSQL, most notably Safari/Webkit on desktop and iOS. One way around this problem is to use an IndexedDB Polyfill or Shim that falls back to WebSQL or even localStorage for non-supporting browsers. The best available polyfill at present is localForage.
Specifications
| Specification | Status | Comment |
|---|---|---|
| Indexed Database API | Candidate Recommendation |