This is the 15th day of my participation in the August More Text Challenge

IndexedDB is a browser-provided local database that can be created and manipulated by web scripts.

background

As the capabilities of the browser continue to increase, more and more sites are considering storing large amounts of data on the client side, which can reduce the amount of data retrieved from the server and bring it directly from the local.

Existing browser data storage schemes are not suitable for storing large amounts of data: cookies are less than 4KB in size, and each request is sent back to the server; LocalStorage is between 2.5MB and 10MB (depending on the browser), does not provide search, and cannot create custom indexes. So a new solution was needed, and this was the context in which IndexedDB was born.

We can view the stored data in IndexedDB using the developer tools:

The characteristics of

In plain English, an IndexedDB is a browser-provided local database that can be created and manipulated by web scripts. IndexedDB allows you to store large amounts of data, provide a lookup interface, and build indexes. These are all things that LocalStorage does not have. In terms of database type, IndexedDB is not a relational database (it does not support SQL query statements) and is closer to a NoSQL database.

IndexedDB has the following features:

(1) Key-value pair storage. IndexedDB uses an object Store internally to store data. All types of data can be stored directly, including JavaScript objects. In the object warehouse, data is stored as “key-value pairs”. Each data record has a corresponding primary key. The primary key is unique and cannot be duplicated, otherwise an error will be thrown.

(2) asynchronous. IndexedDB does not lock the browser and users can still perform other operations, in contrast to LocalStorage, where operations are synchronous. Asynchronous design is designed to prevent massive data reads and writes from slowing down the performance of a web page.

(3) Support transactions. IndexedDB supports transaction, which means that if one of a series of steps fails, the entire transaction is cancelled and the database is rolled back to the state before the transaction occurred, without overwriting only a portion of the data.

IndexedDB is subject to the same origin restriction, and each database corresponds to the domain name that created it. Web pages can only access databases under their own domain names, but not cross-domain databases.

IndexedDB has a much larger storage space than LocalStorage, usually no less than 250MB or even no upper limit.

(6) Support binary storage. IndexedDB can store not only strings but also binary data (ArrayBuffer objects and Blob objects).

role

The use of IndexedDB databases can currently be used directly over HTTP, unlike cacheStorage, which must use HTTPS. Therefore, IndexedDB is quite extensive in terms of application scenarios, and considering that IE10 also supports it, it is almost certain that it will not be a problem in practical projects.

For example, some structured data in a page that does not change often can be stored locally using IndexedDB, which helps improve the interactive performance of the page.

conclusion

This section focuses on IndexedDB, which will be covered in more detail later.

~

Thanks for reading!

~

Learn interesting knowledge, meet interesting friends, shape interesting soul!

Hello everyone, I am the author of “programming Samadhi”, I am king Yi, my public account is “programming Samadhi”, welcome to pay attention, I hope you can give me more advice!

You come, with expectations, I have ink to welcome! You return, no matter gain or loss, only to yu Yun give each other!

Knowledge and skills should be paid equal attention to, internal force and external power should be repaired simultaneously, theory and practice should grasp both hands, both hands should be hard!