Generated by DeepSeek V3.2| IndexedDB | |
|---|---|
| Name | Indexed Database API |
| Author | World Wide Web Consortium |
| Developer | Google, Mozilla Foundation, Apple Inc., Microsoft |
| Released | 18 January 2011 |
| Latest release version | 3.0 |
| Latest release date | 30 January 2024 |
| Programming language | JavaScript |
| Operating system | Cross-platform |
| Platform | Web browser |
| Genre | Web API |
| Website | https://www.w3.org/TR/IndexedDB/ |
IndexedDB. It is a low-level JavaScript Web API for storing significant amounts of structured data, including files and blobs, within a user's web browser. Developed under the auspices of the World Wide Web Consortium, it provides a transactional database system, enabling complex queries and high-performance applications without a network connection. Unlike simpler storage mechanisms, it is designed to support the data requirements of sophisticated web applications like Google Docs, Microsoft Office Online, and complex Progressive Web Apps.
The primary motivation for creating IndexedDB was to address the limitations of earlier client-side storage solutions like Web Storage, which lacked robust querying capabilities and sufficient capacity for large datasets. It allows applications to function offline, a core tenet of the Progressive Web App philosophy championed by companies like Google and Microsoft. Its specification is maintained by the World Wide Web Consortium's Web Applications Working Group, ensuring broad compatibility and standardization across different platforms and implementations.
At its core, IndexedDB is built around an object-oriented architecture centered on object stores, which are analogous to tables in a traditional relational database like SQLite. Each database contains one or more object stores, which hold records consisting of a key and a corresponding value. Indexes can be created on object stores to enable fast searching on properties other than the primary key. All operations are performed within the context of a transaction, which ensures data integrity and follows the ACID properties familiar from systems like Oracle Database and IBM Db2.
The API is asynchronous, using request objects and event handlers to manage operations, preventing the user interface from blocking during data-intensive tasks. Developers open a connection to a database, then perform operations like creating object stores within an upgrade transaction. Common operations include adding records with the `add()` method, retrieving data via a cursor, and querying using an index. The API is accessed through the global `indexedDB` property in supporting web browsers like Google Chrome, Mozilla Firefox, and Microsoft Edge.
IndexedDB enjoys widespread support in all major modern web browsers, including Google Chrome, Mozilla Firefox, Apple Safari, and Microsoft Edge. However, implementations can vary, and certain environments like Internet Explorer have only partial or older versions of the API. Browsers impose storage quotas, which can be managed through the Storage API and may be affected by a user's engagement with a site, a policy often detailed in the Privacy Sandbox initiatives. Private browsing modes in Safari and Firefox may also restrict or clear data upon session closure.
Compared to Web Storage (comprising localStorage and sessionStorage), IndexedDB offers far greater storage capacity, transactional integrity, and complex querying. Unlike Cookies, it is not transmitted with every HTTP request, improving performance. It is a more complex but powerful alternative to Web SQL Database, a deprecated API that used a variant of SQL. For simpler state management, libraries like Redux often pair with IndexedDB for persistence, while newer solutions like the Cache API are designed specifically for network resources.
IndexedDB operates under the same-origin policy, meaning data is siloed and accessible only by web pages from the same domain. This prevents malicious sites from reading data from other origins. However, concerns exist around fingerprinting, as the presence and characteristics of a database can be used to track users across sessions. Browser vendors like those behind Chromium and Gecko implement safeguards, and features like Storage Access API help manage permissions. Data is not encrypted by default, so sensitive information should be protected by the application layer.