The difference between cookie and localStorage

Cookie data is stored in the browser, session data is stored on the server

Cookies are not safe. Others can analyze the cookies stored locally and conduct cookie fraud. Considering the security performance, session should be used as much as possible.

The data saved by a single cookie cannot exceed 4k, and many browsers limit a site to save up to 20 cookies

localStorage features:

1. Life cycle

Persistent local storage, unless the data is actively deleted, the data will never be cleared (permanent)

2. Under the same browser

Localstorage data is shared in all windows of the same origin (consistent protocol, domain name, port)

3. Storage data size

His data storage size is only 5M

4、localStorage

Essentially, it reads strings. If there is too much storage content, it will consume memory space and cause the page to become stuck.

5. Restricted by the same-origin policy

shortcoming:

1. The expiration time cannot be set

2. Only strings can be stored, objects cannot be stored directly

Guess you like

Origin blog.csdn.net/CQXXTXX/article/details/129829861