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.
IndexedDB provides separate APIs for synchronous and asynchronous access. The synchronous API is intended to be used inside workers.
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.
IDBCursoriterates over object stores and indexes.
IDBDatabaserepresents a connection to a database. It's the only way to get a transaction on the database.
IDBFactoryprovides access to a database.
IDBEnvironmentprovides access to a client-side database. It is implemented by window objects.
IDBIndexprovides access to the metadata of an index.
IDBObjectStorerepresents an object store.
IDBOpenDBRequestrepresents a request to open a database.
IDBRequestprovides access to results of asynchronous requests to databases and database objects. It is what you get when you call an asynchronous method.
IDBTransactionrepresents 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) you want.
IDBVersionChangeEventindicates that the version of the database has changed.
Early version of the specification also defined the now removed interface. They are still documented in case you need to update previously writtent code:
IDBVersionChangeRequestrepresents a request to change the version of a database. The way to change the version of the database has since changed (by calling
IDBDatabase.setVersion()) and the interface
IDBOpenDBRequestnow have the functionality of the removed
To get synchronous access to a database, call
open() on the
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.
The following interfaces are used by both the synchronous and the asynchronous APIs.
A powerful example of what IndexedDB can be utilized for on the web is the example by Marco Castelluccio, winner of the IndexedDB Mozilla DevDerby. The winning demo was eLibri, a library and eBook reader application.
|Feature||Chrome||Firefox (Gecko)||Internet Explorer||Opera||Safari (WebKit)|
|Asynchronous API||12||4.0 (2.0)||10||--||--|
|Synchronous API |
(used with WebWorkers)
See bug 701634
|Feature||Android||Firefox Mobile (Gecko)||IE Phone||Opera Mobile||Safari Mobile|
|Asynchronous API||--||6.0 (6.0)||--||--||--|
For Google Chrome, you can have up to 5 MB of storage, by default. Installed apps can have unlimited storage if you set your manifest file to have unlimited storage and your user grants that permission to your app.
- Basic Concepts About IndexedDB
- Using IndexedDB
- Storing images and files in IndexedDB
- A simple TODO list using HTML5 IndexedDB. Note: This tutorial is based on an old version of the specification and does not work on up-to-date browsers: for example, it still uses the removed setVersion() method.
- Indexed Database API specification
- IndexedDB — The Store in Your Browser
- IndexedDB Support in browsers
- IndexedDB Examples