Cette fonction est expérimentale
Puisque cette fonction est toujours en développement dans certains navigateurs, veuillez consulter le tableau de compatibilité pour les préfixes à utiliser selon les navigateurs.
Il convient de noter qu'une fonctionnalité expérimentale peut voir sa syntaxe ou son comportement modifié dans le futur en fonction des évolutions de la spécification.
Ce document est en cours de traduction
IndexedDB est une API de stockage côté client qui permet de gérer des quantités importantes de données structurées et des recherches de haute performance sur ces données en utilisant des index. Alors que DOM Storage est utile pour stocker de petites quantités de données, il est moins utile pour stocker de grandes quantités de données structurées. IndexedDB répond à ce besoin. Cette page est le point d'entrée pour tout ce qui concerne IndexedDB sur MDN - vous y trouverez les liens vers la référence complète de l'API et les guides d'utilisation, le support par le navigateur, et quelques explications sur le concept des clefs.
Concepts des clefs et utilisation
IndexedDB est un sytème de gestion de base de données transactionnel, qui est d'abord déroutant si vous avez l'habitude de travailler avec des bases de données relationnelles, mais qui devient clair assez rapidement. IndexedDB vous permet de stocker et de récupérer des objets qui sont indexés avec une clef. Vous devez spécifier le schéma de la base de données, y ouvrir une connexion, puis récupérer et mettre à jour des données dans une série de transactions.
- Plus d'informations sur les concepts derrière IndexedDB.
- Apprenez à utiliser IndexedDB de manière asynchrone à partir des principes de base grâce à notre guide Using IndexedDB.
- Retrouvez les recommendations de développeurs pour la création de web apps hors-ligne sur notre page Travaux hors-ligne.
Synchrone et asynchrone
IndexedDB comprend à la fois une API asynchrone et une API synchrone. L'API asynchrone peut être utilisée dans la plupart des cas, y compris les Web workers, tandis que l'API synchrone est destinée à être utilisée uniquement avec les Web workers et sera utilisé plus rarement.
Note: Actuellement, la majorité des navigateurs ne supporte pas l'API synchrone.
Limites de stockage
Il n'y a aucune limite à la taille d'un objet sur une base de données unique, cependant il peut y avoir une limite sur la taille totale des bases de données IndexedDB. cette limite (et la façon dont l'interface utilisateur l'interprète) peut varier d'un navigateur à l'autre :
- Firefox n'impose aucune limite à la taille de la base de données IndexedDB. L'interface utilisateur demandera juste la permission de stocker les objets plus gros que 50MB. Ce quota de taille peut être mofifié à travers la préférence
dom.indexedDB.warningQuota(laquelle est définie dans http://mxr.mozilla.org/mozilla-central/source/modules/libpref/src/init/all.js). - Google Chrome : voir 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 (IDBOpenDBRequest); asynchronous operations communicate to the calling application by firing events on IDBRequest objects.
Note: The indexedDB object is prefixed in older browser versions (property mozIndexedDB in Gecko < 16, webkitIndexedDB in Chrome, and msIndexedDB in IE 10).
IDBFactoryprovides access to a database. This is the interface implemented by the global objectindexedDBand is therefore the entry point for the API.IDBCursoriterates over object stores and indexes.IDBCursorWithValueiterates over object stores and indexes and returns the cursor's current value.IDBDatabaserepresents a connection to a database. It's the only way to get a transaction on the database.IDBEnvironmentprovides access to a client-side database. It is implemented by window objects.IDBIndexprovides access to the metadata of an index.IDBKeyRangedefines a range of keys.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) that you want.IDBVersionChangeEventindicates that the version of the database has changed.
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:
IDBVersionChangeRequestrepresents a request to change the version of a database. The way to change the version of the database has since changed (by callingIDBFactory.open()without also callingIDBDatabase.setVersion()), and the interfaceIDBOpenDBRequestnow has the functionality of the removedIDBVersionChangeRequest.IDBDatabaseExceptionrepresents exception conditions that can be encountered while performing database operations.
There is also a synchronous version of the API. The Synchronous API has not been implemented in any browser. It is intended for use with WebWorkers.
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 size. This limit (and the way the user interface will assert it) may vary from one browser to another:
-
Firefox: 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
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
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| Asynchronous API |
24.0 |
10 ms | Pas de support | Pas de support | |
| Synchronous API (used with WebWorkers) |
Pas de support | Pas de support See bug 701634 |
Pas de support | Pas de support | Pas de support |
| Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Asynchronous API | Pas de support | 6.0 (6.0) moz | Pas de support | Pas de support | Pas de support |
For another browser compatibility Matrix see also: When Can I Use IndexedDB
There is also the possibility of using IndexedDB on browsers that support WebSQL by using the IndexedDB Polyfill.
See also
- 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
- IndexedDB Polyfill for browsers that only support WebSQL (e.g. mobile WebKit)
- JQuery IndexedDB plugin

