IndexedDB

This is an experimental feature
Because this feature is still in development in some browsers, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental feature is subject to change in future version of browsers as the spec changes.

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.

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.

Note: This is currently shipped as the property mozIndexedDB in Gecko, webkitIndexedDB in Chrome, msIndexedDB in IE 10 until the standard is finalized.

  • IDBCursor iterates over object stores and indexes.         
  • IDBDatabase represents a connection to a database. It's the only way to get a transaction on the database.
  • IDBFactory provides access to a database.
  • IDBEnvironment provides access to a client-side database. It is implemented by window objects.
  • IDBIndex provides access to the metadata of an index.
  • IDBObjectStore represents an object store.
  • IDBOpenDBRequest represents a request to open a database.
  • IDBRequest provides access to results of asynchronous requests to databases and database objects. It is what you get when you call an asynchronous method.
  • 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) you want.  
  • IDBVersionChangeEvent indicates 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:

Synchronous API

Note: The synchronous APIs of IndexedDB have not yet implemented in any browser. These pages linked here are not current with the IndexedDB specification.

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.

Shared interfaces

The following interfaces are used by both the synchronous and the asynchronous APIs.

Example

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.

Browser compatibility

  • Desktop
  • Mobile

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Asynchronous API 12 webkit 4.0 (2.0) 10 ms -- --
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) -- -- --

Storage limits

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. 

See also

Tags (3)

Edit tags

Attachments (0)

 

Attach file