Take time to organize the session today, cookie, sessionStorage and localStorage but don’t and each usage, summarized a lot of online, to really remember it, it is better to knock yourself to summarize again.

  1. Cookies and sessions are generally used by browsers to record user identity differences: (1) Cookie is saved in the browser side, session is saved in the server side (2) “cookie storage if you do not set the expiration time, then the cookie will be stored in the middle, with the browser closed and closed, if the cookie set expiration time, the cookie will be stored in the hard disk, Only the state-owned enterprise time, cookies will be cleared; ” Session is the object returned by the server to the client, which contains the sessionID information. If there is no sessionID at first, the server will re-create the session object, which contains the sessionID information, and the session information will be saved in the cookie. Each request carries the sessionID (3). The cookie store is only about 4KB, which is not suitable for storing a large amount of information. The session is stored on the server side, so there is no limit, but the storage of multiple servers is a certain pressure
  2. WebStorage: sessionStorage and localStorage
  • First, the storage is 5MB, which is larger than the cookie’s 4KB storage
  • Localstorage can be permanently stored unless manually removed. Sessionstorage is called the browser session window, the browser closed when the sessionstorage data is cleared
  • Webstorage provides the following methods: Key-value pair storage: setItem (key, value) Obtain data: getItem (key) Delete corresponding data: removeItem (key) Clear all: clear () Find index: key (index)
  • Webstorage is also a way of front-end browser communication