Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

24.sessionStorage 、localStorage 和 cookie 之间的区别 #24

Open
webVueBlog opened this issue Mar 11, 2020 · 2 comments
Open

24.sessionStorage 、localStorage 和 cookie 之间的区别 #24

webVueBlog opened this issue Mar 11, 2020 · 2 comments
Labels
浏览器 浏览器

Comments

@webVueBlog
Copy link
Member

共同点:用于浏览器端存储的缓存数据

不同点:

(1)、存储内容是否发送到服务器端:当设置了 Cookie 后,数据会发送到服
务器端,造成一定的宽带浪费;web storage,会将数据保存到本地,不会造成宽
带浪费;

(2)、数据存储大小不同:Cookie 数据不能超过 4K,适用于会话标识;web storage 数据存储可以达到 5M;

(3)、数据存储的有效期限不同:cookie 只在设置了 Cookid 过期时间之前一直
有效,即使关闭窗口或者浏览器; sessionStorage,仅在关闭浏览器之前有效;
localStorage,数据存储永久有效;

(4)、作用域不同:cookielocalStorage 是在同源同窗口中都是共享的;
sessionStorage 在不同的浏览器窗口中共享,即使是同一个页面。

@webVueBlog webVueBlog added the 浏览器 浏览器 label Mar 11, 2020
@webVueBlog
Copy link
Member Author

Common denominator: cache data for browser-side storage

Difference:

(1) whether the stored content is sent to the server: when the Cookie is set, the data will be sent to the server
Service terminal, causing a certain amount of broadband waste; Web storage, which stores data locally, does not create width
With waste;

(2) different data storage sizes: Cookie data cannot exceed 4K, which is suitable for session identification; Web storage data storage can reach 5M;

(3) the validity period of data storage is different: the cookie is kept until the Cookid expiration time is set
Effective, even if the window or browser is closed; SessionStorage, only valid until the browser is closed;
LocalStorage, data storage is permanent;

(4) different scope: cookie and localStorage are Shared in the homologous window;
SessionStorage is Shared in different browser Windows, even on the same page.

@tiyunchen
Copy link

第4点有点问题把,localStorage 是同源的窗口都是共享的,sessionStorage是单个窗口的把

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
浏览器 浏览器
Projects
None yet
Development

No branches or pull requests

2 participants