The difference between cookies, sessionStorage and localStorage

sessionStorage is used to locally store data in a session, which can only be accessed by pages in the same session and destroyed when the session ends. So sessionStorage is not a persistent local storage, but only session-level storage. And localStorage is used for persistent local storage. Unless the data is actively deleted, the data will never expire.

 

The difference between web storage and cookies

 

The concept of Web Storage is similar to that of cookies, the difference is that it is designed for larger storage capacity. The size of the cookie is limited, and every time you request a new page, the cookie will be sent in the past, which is a waste of bandwidth. In addition, the cookie needs to specify the scope and cannot be called across domains.

 

In addition, Web Storage has methods such as setItem, getItem, removeItem, clear, etc. Unlike cookies, front-end developers need to encapsulate setCookie and getCookie by themselves. But cookies are also indispensable: the function of cookies is to interact with the server, as HTTP exists as part of the specification, and Web Storage was only born to "store" data locally.

 

 

It will be added later...  

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326754077&siteId=291194637