The difference between cookies, sessionStorage and localStorage

Interview question: Differences between cookies, sessionStorage and localStorage

 

Please describe the difference between cookies, sessionStorage and localStorage?

A cookie is data (usually encrypted) stored on the user's local terminal (Client Side) by a website in order to identify the user.

Cookie data is always carried in same-origin http requests (even if not needed), and is passed back and forth between browser and server.

sessionStorage and localStorage do not automatically send data to the server, but only save it locally.

 

 

Storage size:

The cookie data size cannot exceed 4k.

Although sessionStorage and localStorage also have storage size limits, they are much larger than cookies and can reach 5M or more.

 

Period:

localStorage stores persistent data, the data will not be lost after the browser is closed unless the data is actively deleted;

sessionStorage data is automatically deleted after the current browser window is closed.

The cookie is set to remain in effect until the cookie expiration time, even if the window or browser is closed

 

 

 

Please describe the difference between cookies, sessionStorage and localStorage?

Cookies are passed back and forth between the browser and the server. sessionStorage and localStorage do not

The storage space of sessionStorage and localStorage is larger;

sessionStorage and localStorage have more rich and easy-to-use interfaces;

separate storage space for sessionStorage and localStorage;

 

 

How to realize the communication between multiple tabs in the browser? (Ali)

Call local storage methods such as localstorge and cookies

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326137868&siteId=291194637