IndexedDB is an API for client-side storage of significant amounts of structured data, which also enables high performance searches of 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
- 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
Operations performed using IndexedDB are done asynchronously, so as not to block the rest of an application's running. IndexedDB originally included both an asynchronous API and a synchronous API; the synchronous API being intended for use only with Web Workers. The synchronous version was removed from the spec because its need was questionable, however it may be reintroduced in the future if there is enough demand from web developers.
There isn't any limit on a single database item's size, however there is in some cases a limit on each IndexedDB database's total size. This limit (and the way the user interface will assert it) varies 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.
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
Connecting to a database
- Provides access to IndexedDB functionality. It is implemented by the
- Provides access to a database. This is the interface implemented by the global object
indexedDBand is therefore the entry point for the API.
- Represents a request to open a database.
- Represents a connection to a database. It's the only way to get a transaction on the database.
- Generic interface that handles database requests and provides access to results.
Retrieving and modifying data
- 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 readwrite) that you want.
- Represents an object store that allows access to a set of data in an IndexedDB database, looked up via primary key.
- Also allows access to a subset of data in an IndexedDB database, but uses an index to retrieve the record(s) rather than the primary key. This is sometimes faster than using
- Iterates over object stores and indexes.
- Iterates over object stores and indexes and returns the cursor's current value.
- Defines a range of keys that can be used to retrieve data from a database in a certain range.
Custom event interfaces
This specification fires events with the following custom interface:
IDBVersionChangeEventinterface indicates that the version of the database has changed, as the result of an
IDBOpenDBRequest.onupgradeneededevent 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:
- 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 calling
IDBDatabase.setVersion), and the interface
IDBOpenDBRequestnow has the functionality of the removed
- Represents exception conditions that can be encountered while performing database operations.
- 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.
- Storing images and files in IndexedDB
|Feature||Chrome||Firefox (Gecko)||Internet Explorer||Opera||Safari (WebKit)|
|10.0 (10.0) moz
|Feature||Android||Firefox Mobile (Gecko)||Firefox OS||IE Phone||Opera Mobile||Safari Mobile|
|Basic support||4.4||22.0 (22.0)||1.0.1||10||22||8|
Note: Some older browsers don't support IndexedDB but do support WebSQL. 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.
|Indexed Database API
The definition of 'IDBEnvironment' in that specification.
- localForage: A Polyfill providing a simple name:value syntax for client-side data storage, which uses IndexedDB in the background, but falls back to WebSQL and then localStorage in browsers that don't support IndexedDB.
- dexie.js: A wrapper for IndexedDB that allows much faster code development via nice, simple syntax.