Html5 browser database and html5 Database
I. Why do I use a browser database?
With the increasing processing capability of browsers, more and more websites are considering storing a large amount of data on the client, which can reduce the time for users to wait for data to be obtained from the server.
Ii. Reasons for using IndexedDB
Existing browser-side data storage solutions are not suitable for storing a large amount of data: Cookies cannot exceed 4 kb, and each request is sent back to the server. The Window. name attribute lacks security,
There is no unified standard; localStorage is between MB and 10 MB (different browsers ). Therefore, a new solution is required, which is the background of IndexedDB.
3. What is IndexedDB?
In general, IndexedDB is a browser-side database that can be created and operated by web script programs. It allows you to store a large amount of data, provide search interfaces, and create indexes.
These are not available in localStorage. In terms of the database type, IndexedDB is not a relational database (SQL query statements are not supported) and is closer to NoSQL databases.
Iv. IndexedDB features.
(1) store key-value pairs. IndexedDB uses an object store to store data. All types of data can be directly stored, including JavaScript objects. In the object repository,
Data is saved as a "key-Value Pair". Each data has a corresponding key name. The key name is unique and cannot be duplicated. Otherwise, an error is thrown.
(2) asynchronous. The browser is not locked during the IndexedDB operation. You can perform other operations. This is a comparison with localStorage. The operations of the latter are synchronized. Asynchronous Design is designed to prevent reading and writing large amounts of data and slow down the performance of web pages.
(3) supports transactions. IndexedDB supports transactions, which means that the entire transaction is canceled as long as one failed step in a series of operation steps, and the database is returned to the status before the transaction occurs, there is no scenario where only a part of data is rewritten.
(4) Restrictions on the same domain IndexedDB are also restricted by the same domain. Each database corresponds to the domain name for creating the database. Webpages from different domain names can only access databases under their own domain names, but cannot access databases under other domain names.
(5) large storage space: the storage space of IndexedDB is much larger than that of localStorage. Generally, the storage space is not less than 250 MB. The Storage Limit of IE is 250 MB, Chrome and Opera are a certain percentage of the remaining space, and Firefox has no upper limit.
(6) binary storage is supported. IndexedDB not only stores strings, but also binary data.
Currently, Chrome 27 +, Firefox 21 +, Opera 15 +, and IE 10 + support this API, but Safari does not.