Home > Web Front-end > JS Tutorial > The difference between localStorage. sessionStorage and Cookie

The difference between localStorage. sessionStorage and Cookie

hzc
Release: 2020-06-24 09:32:06
forward
2174 people have browsed it

●Differences in storage size:

  1. The size of localStorage is generally 5M

  2. The size of sessionStorage is generally 5M

  3. The size of cookies is generally 4K

●Different validity periods:

1. The validity period of localStorage is permanent unless you delete it manually.

2.sessionStorage is valid in the current session and will be cleared when the page or browser is closed.

3. Cookies are valid before the set validity period, and will expire when the validity period expires.

●Communication with the server

1.localStorage does not participate in server-side communication.

2.sessionStorage does not participate in server-side communication.

3. Cookies participate in server-side communication and will be stored in the http header information every time. (If you use cookies to save too much data, it will cause performance problems)

●Detailed explanation of the difference between the scopes of localStorage and sessionStorage 1. Different browsers cannot share information in localStorage or sessionStorage. 2. Different pages of the same browser can share the same localStorage (the pages belong to the same domain name and port), but sessionStorage information cannot be shared between different pages or tabs.

Generally store things like shopping carts, because the validity period is permanent and the size is about 5m, so localStorage is more commonly used in the front end, cookie It is not used much because it is not safe. It is generally used as a secret key (token), the back-end stores the password, and gives the front-end token to open

Recommended tutorial: "JS Tutorial

The above is the detailed content of The difference between localStorage. sessionStorage and Cookie. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template