除了非持久化和仅作用于当前窗口之外,会话存储相对于本地存储是否有任何好处(性能,数据访问等)?
当前回答
sessionStorage为每个给定的源维护一个单独的存储区域,该存储区域在页面会话期间可用(只要浏览器打开,包括页面重新加载和恢复)。 localStorage做同样的事情,但是即使浏览器关闭并重新打开,它仍然存在。
我从Web存储API中获得了这个
其他回答
其他几点可能有助于理解本地存储和会话存储之间的区别
Both local storage and session storage are scoped to document origin, so https://mydomain.example/ http://mydomain.example/ https://mydomain.example:8080/ All of the above URL's will not share the same storage. (Notice path of the web page does not affect the web storage) Session storage is different even for the document with same origin policy open in different tabs, so same web page open in two different tabs cannot share the same session storage. Both local and session storage are also scoped by browser vendors. So storage data saved by IE cannot be read by Chrome or FF.
localStorage和sessionStorage都扩展了Storage。除了sessionStorage的“非持久性”之外,它们之间没有任何区别。
也就是说,存储在localStorage中的数据将一直存在,直到显式删除为止。所做的更改将被保存,并可用于当前和将来对站点的所有访问。
对于sessionStorage,更改仅适用于每个选项卡。所做的更改将被保存,并可用于该选项卡中的当前页面,直到关闭该选项卡为止。一旦关闭,存储的数据就会被删除。
localStorage和sessionStorage之间的主要区别是sessionStorage每个选项卡都是唯一的。如果关闭选项卡,sessionStorage将被删除,而localStorage不会。你也不能在标签之间通信:)
另一个微妙的区别是,例如在Safari(8.0.3)上,localStorage限制为2551 k字符,而sessionStorage有无限的存储空间
在Chrome (v43)中,localStorage和sessionStorage都被限制在5101 k个字符(正常/隐身模式没有区别)
在Firefox上,localStorage和sessionStorage都被限制为5120 k字符(正常模式和私有模式之间没有区别)
速度没有任何差异:)
移动Safari和移动Chrome也有一个问题,私人模式Safari和Chrome的最大空间为0KB
性能方面,我的(粗略的)测量在1000次写入和读取时没有发现差异
安全方面,从直觉上看,localStore可能会在sessionStore之前关闭,但没有具体的证据-也许其他人会?
功能方面,与digitalFresh一致
sessionStorage与localStorage相同,只是它只存储一个会话的数据,并且当用户关闭创建它的浏览器窗口时,它将被删除。
推荐文章
- 在React Native中使用Fetch授权头
- 为什么我的球(物体)没有缩小/消失?
- Twitter Bootstrap 3 Sticky Footer
- 如何使用jQuery检测页面的滚动位置
- if(key in object)或者if(object. hasownproperty (key)
- 一元加/数字(x)和parseFloat(x)之间的区别是什么?
- angularjs中的compile函数和link函数有什么区别
- 删除绑定中添加的事件监听器
- CSS在特定的“内联块”项之前/之后换行
- 很好的初学者教程socket.io?
- 点击下载Href图片链接
- HtmlSpecialChars在JavaScript中等价于什么?
- 我如何删除背景图像在css?
- 如何克服HTML表单嵌套的限制?
- React: 'Redirect'没有从' React -router-dom'中导出