除了非持久化和仅作用于当前窗口之外,会话存储相对于本地存储是否有任何好处(性能,数据访问等)?
当前回答
The only difference is that localStorage has a different expiration time, sessionStorage will only be accessible while and by the window that created it is open. localStorage lasts until you delete it or the user deletes it. Lets say that you wanted to save a login username and password you would want to use sessionStorageover localStorage for security reasons (ie. another person accessing their account at a later time). But if you wanted to save a user's settings on their machine you would probably want localStorage. All in all:
localStorage—用于长期使用。 sessionStorage—当您需要存储更改的东西或临时的东西时使用
其他回答
sessionStorage与localStorage相同,只是它只存储一个会话的数据,并且当用户关闭创建它的浏览器窗口时,它将被删除。
会话存储和本地存储在行为上是相同的,除了一个是本地存储将存储数据,直到用户删除缓存和cookie,会话存储数据将保留在系统中,直到我们关闭会话i,直到我们关闭会话存储创建的窗口。
其他几点可能有助于理解本地存储和会话存储之间的区别
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.
在我看来,会话存储相对于本地存储的优势在于,它在Firefox中具有无限的容量,并且不会持续比会话更长的时间。(当然这取决于你的目标是什么。)
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
推荐文章
- 撇号的HTML代码
- 如何在Typescript中解析JSON字符串
- Javascript reduce()在对象
- 在angularJS中& vs @和=的区别是什么
- 错误"Uncaught SyntaxError:意外的标记与JSON.parse"
- JavaScript中的querySelector和querySelectorAll vs getElementsByClassName和getElementById
- 给一个数字加上st, nd, rd和th(序数)后缀
- 如何以编程方式触发引导模式?
- setTimeout带引号和不带括号的区别
- 为什么我的CSS3媒体查询不能在移动设备上工作?
- 在JS的Chrome CPU配置文件中,'self'和'total'之间的差异
- 用javascript检查输入字符串中是否包含数字
- 如何使用JavaScript分割逗号分隔字符串?
- 在Javascript中~~(“双波浪号”)做什么?
- 谷歌chrome扩展::console.log()从后台页面?