The following comparisons are made from 3 aspects: 1, Capacity: Cookies are only 4kb,localstorage and sessionstorage maximum capacity 5m2, will be carried into Ajax: Cookies are transmitted by each request to the server, which can affect the efficiency of acquiring resources, Localstorage and Sessionstorage only use the data when requested. It makes it possible to store large amounts of data without compromising site performance. 3,api Ease of Use: cookies require encapsulation to be used, localstorage and sessionstorage are easy
HTML5 is designed for storage and provides two new ways to store data on the client: Localstorage and Sessionstorage
- Localstorage-Data storage with no time limit, data is still available after the next day, the second week, or the next year.
- Sessionstorage-Data storage for a session, when the user closes the browser window, it is deleted.
A maximum capacity of 5M, data is not passed by each server request, but only when the data is used on request. It makes it possible to store large amounts of data without compromising site performance.
For different sites, the data is stored in different regions, and a Web site can only access its own data.
HTML5 uses JavaScript to store and access data.
API easy to use Localstorage.setitem (key,value) Localstorage.getitem (key) Note: iOS Safari Stealth mode (privacy mode) Localstorage and Sessionstroage will be error recommended unified use of the Try-catch encapsulation cookie itself for client and server communication but it has local storage capabilities, so it is "borrowed" Cookies are used to store the disadvantage of storage is too small, only 4KB all HTTP requests are carried, will affect the efficiency of obtaining resources API needs encapsulation to use Document.cookie = ... Refer to other links for details: https://www.cnblogs.com/kaixin3946/p/6042014.html
The difference between HTML5 Web Storage and cookies