What is Web Storage? Detailed explanation of Web Storage

Web Storag is a very important feature introduced by HTML5. It can store data locally, such as saving user preferences, checked status of check boxes, and default values ​​filled in text boxes. When the user refreshes the web page in the browser, the web page can know some of the modifications made by the user through Web Storage, without the need to store the content modified by the user on the server side.

Web Storage is similar to Cookie, but it can reduce network traffic compared to Cookie, because the data stored in Web Storage will not be sent to the server, while the data stored in Cookie will be automatically sent to the server by the browser through HTTP requests. Storing data in WebStorage reduces unnecessary data transfer back and forth between the browser and the server.

Web Storage contains two key objects, namely the localStorage object and the sessionStorage object. They are both instances of Web Storage, so they can all use the methods and properties provided by the Web Storage interface. The localStorage object is used for local storage, and the sessionStorage object is used for regional storage.

Web Storage has the following 5 characteristics:

(1) It is convenient to set and read data.

(2) Large capacity, can store approximately 5MB of data.

(3) Only strings can be stored. If you want to store JSON objects, you can use the JSON.stringify() and JSON.parseO methods to serialize and deserialize respectively.

(4) Local data can be obtained instantly. With the browser's cache, the entire page and data can be saved locally. Reading data locally is much faster than obtaining data from the server through the network, and the cached content in the web page can be displayed immediately.

(5) Data can be temporarily stored. Many times the data only needs to be used while the user is browsing a single page, and the data can be discarded after the page is closed. In this case, sessionStorage is very convenient.
Currently, the mainstream web browsers on the market all support HTML5 Web Storage to a certain extent, and both iOS and Android platforms have good support for Web Storage. Currently, the mainstream mobile phones and tablet computers on the market rely on these two platforms, so in actual development, there is basically no need to worry about the support of Web Storage by the web browser of the mobile device.

Guess you like

Origin blog.csdn.net/cz_00001/article/details/132989895