First, Cookie and session
The common thing about cookies and sessions is that both the cookie and the session are used to track the user's identity in a browser.
Session refers to the period of time when a visitor arrives from a particular page until it leaves.
The difference between a cookie and a session:
1.cookie data is saved on the client, session data is saved on the server
2.cookie is not very safe, others can analyze cookies stored locally in cookie spoofing, taking into account that security should use the session
II. Cookies and Web Storage
1.web storage is a local storage method in the H5, including two kinds: Sessionstorage and localstorage.
Sessionstorage is a 乬 that is used to store a session locally, which is accessible only to pages in the same session and destroyed when the session ends, and is a session-level store that is not persistent local storage
Localstorage is used for persistent local storage, and data will never expire unless the data is actively deleted.
2.cookie refers to certain websites in order to identify users, the session tracking exists in the user's local terminal data, that is, the browser cache.
The difference between cookies and Web storage is that the latter is designed to overcome some of the drawbacks of the former.
3.cookie and Web Storage differences
3.1.cookie is limited in length and size, and the length of each cookie cannot exceed 4KB, otherwise it will be truncated. WebStorage has a large capacity, each domain Chrome,firefox and opera is 5m,ie is 10M.
3.2. Each request for a new page cookie will be sent in the past, each request will not carry WebStorage content
3.3.cookie requires a scope to be specified and cannot be called across domains. Web Storage can store data in localstorage and need to be used to extract several of them under their own domain to solve cross-domain issues.
The role of 3.4.cookie is to interact with the server, which exists as part of the HTTP specification, and the Web storage only exists as a local store
3.5.cookie requires front-end development of its own package Setcookie,getcookie, and WebStorage has Setitem,getitem,removeitem,clearitem and other methods
4. Summary
In general, Web Storage has its benefits, but it does not completely replace cookies, just that it solves the hassle of having to use cookies in some previous scenarios.
Cookies and Session,cookie and Web Storage