$ window.sessionStorage vs $ cookieStore [英] $window.sessionStorage vs $cookieStore

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

问题描述

使用$ cookieStore和& window.sessionStorage有什么区别?是否有时候应该使用另一个?安全问题?

What is the difference between using $cookieStore and &window.sessionStorage? Are there times when one should be used over the other? Security Issues?

这是我所知道的:

AngularJS文档声明$ cookieStore服务受会话Cookie支持( https://docs.angularjs.org/api/ngCookies/service/ $ cookieStore)。所以,看起来与$ cookieStore存储的信息绑定到使用它的窗口/选项卡。这是通过在$ cookieStore的代码中使用神秘的$ browser服务来确认的: https://github.com/angular/angular.js/blob/master/src/ngCookies/cookies.js#L125

The AngularJS docs state that the $cookieStore service is backed by "session cookies" (https://docs.angularjs.org/api/ngCookies/service/$cookieStore). So, it appears that information stored with $cookieStore is tied to the window/tab where it is used. This is affirmed by the use of the mysterious $browser service in the code for $cookieStore: https://github.com/angular/angular.js/blob/master/src/ngCookies/cookies.js#L125.

但是,由于$ browser是一个内部服务,可能会发生变化,我看不到它是如何存储数据,看看它是否类似于sessionStorage。

However, since $browser is an internal service and subject to change, I can't see how it is storing the data, to see if it is similar to sessionStorage.

相同的浏览器/标签/窗口范围似乎适用于$ window.sessionStorage(范围of sessionStorage and localStorage )。

The same browser/tab/window scope seems to apply to $window.sessionStorage (Scope of sessionStorage and localStorage).

推荐答案

$ cookieStore使用会话Cookie意味着数据将以Cookie作为范围到会话,即不持久。 Cookie范围限于其注册的特定域,但可以在子域之间共享。关于cookie存储库的一大关键是,这些cookie值将被发送到服务器以获得对该域的任何请求。它将在同一域中的同一会话中的窗口和标签页之间共享。

$cookieStore using session cookies means that data is persisted as cookies that are scoped to the session, i.e. not persistent. A cookie is scoped to the particular domain it is registered on, but may be shared between subdomains. The big deal about the cookie store is that those cookie values will be sent to the server for any requests to that domain. It would be shared between windows and tabs in the same session on the same domain.

$ window.sessionStorage只是访问window.sessionStorage,这与真正无关角度。通过$窗口访问它只是让你使用嘲笑版本的$窗口更容易测试的能力。会话存储的范围限制到当前窗口,因此与Cookie不同,如果您打开一个新的选项卡到完全相同的URL,它将是一个新的sessionStorage对象。还有比Cookie更多的存储空间。一个cookie限制在4K,sessionStorage可以不同浏览器,但通常大约5MB。

$window.sessionStorage just accesses the window.sessionStorage, which really has nothing to do with Angular. Accessing it through $window just gives you the ability to test more easily using a mocked version of $window. Session storage is scoped to the current window, so unlike cookies, if you open a new tab to the exact same URL it will be a new sessionStorage object. There is also more room for storage than cookies. A cookie is limited to 4K, sessionStorage can differ per browser but is usually around 5MB.

还有window.localStorage(或$ window.localStorage)基本相同作为sessionStorage,除了它的作用域(两个选项卡可以共享相同的数据 - 甚至一个存储事件,所以你可以找出什么时候另一个标签页更改它),并保持在您关闭浏览器。

There's also window.localStorage (or $window.localStorage) which is basically the same as sessionStorage, except it is scoped by domain (two tabs can share the same data - there's even a storage event so you can find out when another tab changes it) and persists when you close your browser.

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

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