localStorage 与 sessionStorage 与 cookie [英] localStorage vs sessionStorage vs cookies

查看:28
本文介绍了localStorage 与 sessionStorage 与 cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个应用程序中工作,我需要在用户登录期间保留一些数据,我有这个问题,它们之间有什么区别localStorage、sessionStorage、cookies ???

I am working in an app where I need to keep some data during the user is logged in and I have that question, what is the difference among localStorage, sessionStorage, cookies ???

我在问我可以用什么来持久化DOM中的一些数据,即使用户刷新页面,有人说:使用sessionStorage,或localStorage,然后,有人想出了使用ngCookies 因为它适用于所有浏览器,但是,我应该使用哪个?

I was asking what can I use in order to persist some data in the DOM, even if the user refresh the page, some people says: use sessionStorage, or localStorage, then, someone came up with the idea of use ngCookies because it works in every browser, but, which should I use ?

推荐答案

localStoragesessionStorage 都是所谓的 WebStorage 和特性HTML5.

localStorage and sessionStorage are both so-called WebStorages and features of HTML5.

localStorage 存储信息,只要用户不删除它们.

localStorage stores information as long as the user does not delete them.

sessionStorage 会在会话期间存储信息.通常直到用户关闭选项卡/浏览器.

sessionStorage stores information as long as the session goes. Usually until the user closes the tab/browser.

cookies 只是 cookie,受旧浏览器支持,通常是使用上述 WebStorages 的框架的后备.

cookies are simply cookies, which are supported by older browsers and usually are a fallback for frameworks that use the above mentioned WebStorages.

相比之下,cookie 可以存储的信息比 WebStorages 少得多,而且 WebStorages 中的信息永远不会传输到服务器.

In contrast cookies can store way less information then WebStorages and the information in WebStorages is never transferred to the server.

请记住,欧盟有一项法规要求网站通知其用户有关 Cookie 的使用情况.我不知道这是否也适用于 WebStorages

Keep in mind that the EU has a regulation that requires websites to inform their users about the usage of cookies. I dont know whether this also applies to WebStorages

这篇关于localStorage 与 sessionStorage 与 cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆