Web Storage?

Using HTML5, you can store the user’s browsing data locally.

The main purpose of cookies is to overcome some of the limitations of cookies, when data needs to be tightly controlled on the client side without continually sending data back to the server

Main objectives:

1. Provide a way to store session data outside of cookies

2. Provide a mechanism for storing large amounts of data that can exist across sessions

 

Web Storage is classified into two types: SessionStorage and localStorage

SessionStorage stores data in session, and when the entire browser is closed, the data is lost (page refresh does not erase data, only links opened in the current page can access SessionStorage data, Use window.open and change localtion.href to retrieve sessionStorage data.)

LocalStorage keeps the data locally on the client and will not let the data disappear unless it is actively deleted

 

Difference between Web Storage and cookies

 

First, the storage space is different

1. A Web Storage provides 5M Storage space (depending on the browser), and a Cookie provides 4K Storage space

2.Web Storage Each domain (including subdomains) has independent Storage space. Each Storage space is completely independent, preventing data confusion

 

Interaction with the server

1. Data in a Web Storage is only locally stored and does not interact with the server

2. The content of cookies will be sent to the server along with the request (cookies will be sent to the server every time a new page is requested, virtually causing broadband waste)

 

Three, interfaces,

1.Web Storage provides many rich and easy to use interfaces, with setItem, removeItemgetItem, clear, key and other methods, operation data more simple

2. Cookies need to encapsulate setCookie, getCookie, etc