Interview Topics:

  • Description Cookie localStorage sessionStorage distinction
    • capacity
    • API for ease of use
    • Whether to send an HTTP request

cookie

  • It is used for browser and server communication
  • Is’ borrowed ‘to local storage
  • Document. cookie = ‘… ‘to modify

Disadvantages:

  • Cookie storage size, maximum 4KB
  • HTTP requests must be sent to the server to increase the amount of requested data
  • Only document.cookie = ‘… ‘to modify, too crude
// The same key overwrites the document. Cookie ='a=100; b=200; 'Copy the code

LocalStorage and sessionStorage

  • HTML5 is specifically designed for storage and can hold up to 5M

  • The API is simple to use setItem getItem

  • Will not be sent out with the HTTP request

  • LocalStorage data is permanently stored unless deleted by code or manually

  • SessionStorage data only exists in the current session and is cleared when the browser is closed

  • Generally use localStorage will be more