Differences between localStorage, sessionStorage and cookies
Published at 2024-05-14 19:25:04Viewed 411 times
Common article
Please reprint with source link
We can store tokens and user information in localStorage, sessionStorage, or cookies. They are all ways of browser that store data locally. In browser, open the developer mode, and click Application
. Then you can view the messages stored in the localStorage, sessionStorage, and cookies on the website.
Here are some differences between LocalStorage, SessionStorage, and Cookies:
- Data in LocalStorage have no lifecycle which means it will never expire, and need to be manually deleted. It is merely stored locally in your computer and will not be sent to the backend server. LocalStorage occupies less space.
- SessionStorage is similar to LocalStorage, but data in SessionStorage have a lifecycle. In other words, it will expire and be automatically deleted after you close the browser which closes any session. SessionStorage occupies less space.
- Cookies also have a lifecycle, and are automatically deleted upon expiration. However, they will be sent to the backend server whenever the browser sends requests. Moreover, cookies occupy much more space.
0 人喜欢
Comments
There is no comment, let's add the first one.