cookie sessionStorage localStorage difference?

1.cookie

  • Storage period: valid forever, unless manually deleted;
  • Data size: generally around 5-10MB;
  • Scope: can be accessed in all pages under the same domain name;
  • Purpose: Long-term storage of data on the client side, suitable for data that needs to be saved across multiple sessions.

2.sessionStorage

  • Storage period: Persistently valid until the end of the current session, invalid when the browser is closed;
  • Data size: generally around 5-10MB;
  • Scope: limited to the current window or tab;
  • Purpose: Temporary storage of data on the client side, suitable for temporary data that needs to be saved in a single session.

3.localStorage

  • Storage period: valid forever, unless manually deleted;
  • Data size: generally around 5-10MB;
  • Scope: can be accessed in all pages under the same domain name;
  • Purpose: Long-term storage of data on the client side, suitable for data that needs to be saved across multiple sessions.
  • The type of saved value is restricted, the browser cannot read it in private mode, and cannot be crawled;

4.indexedDB

  • browser built-in database
  • Transaction: IndexedDB uses transactions to ensure data consistency and integrity.
  • Object Store: IndexedDB uses an object storage mechanism to store and retrieve data.
  • Index (Index): An index in IndexedDB is composed of one or more attributes, and each attribute can be selected to be unique or non-unique.
  • Asynchronous operation (Asynchronous): In order to avoid blocking other parts of the application, IndexedDB uses asynchronous operations for all data reading and writing.

Guess you like

Origin blog.csdn.net/Xxf909011/article/details/130644289