This chapter mainly covers WebStorage and local databases. Among them, WebStorage is the optimization of cookies. The local database is a new function of HTML5. using it, you can create a database on the client, which greatly reduces the burden on the server, accelerate Data Access
Preface
This chapter mainly covers Web Storage and local databases, where Web Storage optimizes cookies. Local databases are a new function of HTML5. You can use this function to create a database on the client.
This greatly reduces the burden on the server and accelerates data access.
To learn this chapter, you must master the basic concepts of Web Storage and understand the usage and differences between sessionStorage and localStorage.
Master the use of local databases
What is WebStorage?
As mentioned above, webstorage is optimized for cookies. In HTML4, cookies are used to store user data on the client. The following problems have been found during long-term use:
The size limit is 4 kbcookie, which is sent along with the HTTP transaction each time. It is complicated to waste bandwidth to operate the cookie correctly (this should be considered)
Due to the above problems, HTML5 proposed WebStorage as a new local storage technology for the client.
The Code is as follows:
The Web Storage technology stores data locally on the web Client. Specifically, it can be divided into two types:
SessionStrage:
Session refers to the period from the time when a user browses a website to the time when the user closes the website, the validity period of the session object is only so long.
LocalStorage:
Save the data on the client hardware device, no matter what it is, that is, the data is still in the next time you open the computer.
The difference between the two is temporary storage and long-term storage.
Example
The Code is as follows:
Simple Application
Web Storage experiment
SessionStorage LocalStorage
Save data
Read data