The difference between cookies, sessionStorage (session storage) and localStrorage (local storage)

1. The difference between cookies, sessionStorage and localStrorage

  1. Cookies are passed back and forth between the browser and the server . sessionStorage and localStorage will not;
  2. The storage space of sessionStorage and localStorage is larger;
  3. SessionStorage and localStorage have more rich and easy-to-use interfaces;
  4. Separate storage space for sessionStorage and localStorage;

2. The difference and characteristics of the three

  1. Cookies are data (usually encrypted) that the website stores on the user's local terminal (Client Side) in order to identify the user.
  2. The cookie data is always carried in the same http request (even if it is not needed), that is, it will be passed back and forth between the browser and the server.
  3. sessionStorage and localStorage will not automatically send the data to the server, only save it locally
  4. Storage size: The size of
    cookie data cannot exceed 4K .
    Although sessionStorage and localStorage also have storage size limitations, they are much larger than cookies and can reach 5M or more .
  5. Period of time:
    localStorage: store persistent data, the data will not be lost after the browser is closed unless the data is deleted actively;
    sessionStorage: the data will be automatically deleted after the current browser window is closed.
    Cookie: the set cookie will remain valid until the expiration time of the cookie , even if the window or browser is closed .

Guess you like

Origin blog.csdn.net/Serena_tz/article/details/113938662