javascript|HTML5本地存储与会话存储

本文翻译自:HTML5 Local storage vs. Session storage
除了非持久性和仅限于当前窗口的范围之外,对本地存储的会话存储有任何好处(性能,数据访问等)吗?
#1楼
参考:https://stackoom.com/question/NAou/HTML-本地存储与会话存储
#2楼
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有不同的到期时间, sessionStorage只能在创建它的窗口打开时才能访问。
localStorage lasts until you delete it or the user deletes it. localStorage持续到您删除它或用户删除它为止。
Lets say that you wanted to save a login username and password you would want to use sessionStorage over localStorage for security reasons (ie. another person accessing their account at a later time). 假设您想要保存一个登录用户名和密码,出于安全原因(即,稍后访问其帐户的其他人),您希望在localStorage上使用sessionStorage
But if you wanted to save a user's settings on their machine you would probably want localStorage . 但是如果你想在他们的机器上保存用户的设置,你可能需要localStorage All in all: 总而言之:

localStorage - use for long term use. localStorage - 用于长期使用。
sessionStorage - use when you need to store somthing that changes or somthing temporary sessionStorage - 当你需要存储变化的东西或临时的东西时使用
#3楼
sessionStoragelocalStorage相同,只是它只存储一个会话的数据,当用户关闭创建它的浏览器窗口时,它将被删除。
#4楼
Ya会话存储和本地存储在行为上是相同的,除了本地存储之一将存储数据,除非用户删除缓存并且cookie和会话存储数据将保留在系统中直到我们关闭会话i,直到我们关闭会话存储创建窗口。
#5楼
Few other points which might be helpful to understand differences between local and session storage 其他几点可能有助于理解本地和会话存储之间的差异

  1. Both local storage and session storage are scoped to document origin, so 本地存储和会话存储都限定为文档原点,因此
    https://mydomain.com/ https://mydomain.com/
    http://mydomain.com/ http://mydomain.com/
    https://mydomain.com:8080/ https://mydomain.com:8080/
    All of the above URL's will not share the same storage. 以上所有URL都不会共享相同的存储空间。 (Notice path of the web page does not affect the web storage) (网页的通知路径不影响网络存储)
  2. 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. 即使对于在不同选项卡中打开具有相同原始策略的文档,会话存储也是不同的,因此在两个不同选项卡中打开的相同网页不能共享相同的会话存储。
  3. 【javascript|HTML5本地存储与会话存储】 Both local and session storage are also scoped by browser vendors . 本地和会话存储也由浏览器供应商确定范围。 So storage data saved by IE cannot be read by Chrome or FF. 因此,Chrome或FF无法读取IE保存的存储数据。
Hope this helps. 希望这可以帮助。
#6楼
The advantage of the session storage over local storage, in my opinion, is that it has unlimited capacity in Firefox, and won't persist longer than the session. 在我看来,会话存储优于本地存储的优势在于它在Firefox中具有无限容量 ,并且不会比会话持续更长时间。 (Of course it depends on what your goal is.) (当然这取决于你的目标。)

    推荐阅读