localStorage替换Cookie? [英] localStorage a replacement for cookies?

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

问题描述

新引入的html5中的localStorage工具是否替代了Cookie? localStorage帮助使http从无状态到有状态。或者是localStorage除了cookie之外。
您仍然需要使用Cookie来跟踪用户,甚至可以在localStorage中执行此操作吗?

Is the newly introduced localStorage facility in html5 a replacement for cookies? Does localStorage help in making the http from stateless to stateful. Or is the localStorage an addition to the cookies.
Do you still need to use cookies to track the user or even that can be done ny localStorage?

推荐答案

允许客户端javascript在本地机器上保存状态(如果支持LocalStorage)。这是客户端javascript可能使用cookie的一个事情,但是Cookie也用于LocalStorage无法替换的其他事情。

Local Storage allows client-side javascript to save state on a local machine (if LocalStorage is supported). That is one thing that client-side javascript might use cookies for, but cookies are also used for other things that LocalStorage cannot replace.

例如,LocalStorage从来不会被服务器看到,因此如果服务器想要跟踪一些客户端状态本身或在域上的多个页面上跟踪某些内容,服务器不能使用LocalStorage,并且可能仍然使用Cookie。域的Cookie会通过该域中的每个请求发送到服务器(因此可以在网站的所有页面上进行身份验证登录)。这是LocalStorage不能做的。

For example, LocalStorage is never seen by a server so if a server wants to keep track of some client state itself or track something across multiple pages on a domain, then the server can't use LocalStorage for that and will likely still use cookies. Cookies for a domain are sent to the server with each request on that domain (thus enabling things like authenticated login across all pages in a site). This is something that LocalStorage cannot do.

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

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