HTML5 Local storage vs. Session storage

后端 未结 10 2540
甜味超标
甜味超标 2020-11-22 03:16

Apart from being non persistent and scoped only to the current window, are there any benefits (performance, data access, etc) to Session Storage over Local Storage?

10条回答
  •  礼貌的吻别
    2020-11-22 04:08

    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 - use for long term use.
    sessionStorage - use when you need to store somthing that changes or somthing temporary

提交回复
热议问题