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 个解决方案
#1
541
localStorage
and sessionStorage
both extend Storage
. There is no difference between them except for the intended "non-persistence" of sessionStorage
.
localStorage和sessionStorage都可以扩展存储空间。它们之间并没有区别,除非是有意的sessionStorage的“非持久性”。
That is, the data stored in localStorage
persists until explicitly deleted. Changes made are saved and available for all current and future visits to the site.
也就是说,存储在localStorage中的数据一直存在,直到被显式删除。所做的更改保存并可用于所有当前和将来访问该站点的访问。
For sessionStorage
, changes are only available per window (or tab in browsers like Chrome and Firefox). Changes made are saved and available for the current page, as well as future visits to the site on the same window. Once the window is closed, the storage is deleted.
对于sessionStorage,更改只能在每个窗口中使用(或在Chrome和Firefox等浏览器中使用)。所做的更改保存并可用于当前页面,以及将来访问同一窗口的站点。一旦窗口关闭,存储将被删除。
#2
132
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 sessionStorage
over 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只能是可访问的,而创建它的窗口是打开的。localStorage一直持续到您删除它或用户删除它为止。假设您想要保存登录用户名和密码,出于安全考虑,您希望使用sessionStorageover localStorage。另一个人在以后访问他们的帐户。但是,如果您想要在他们的机器上保存用户的设置,您可能需要localStorage。总而言之:
localStorage
- use for long term use.sessionStorage
- use when you need to store somthing that changes or somthing temporary
localStorage -用于长期使用。sessionStorage——当您需要存储一些临时更改或临时的内容时使用。
#3
92
Few other points which might be helpful to understand differences between local and session storage
很少有其他的点可能有助于理解本地和会话存储之间的差异。
-
Both local storage and session storage are scoped to document origin, so
本地存储和会话存储都被限定为文档的来源。
https://mydomain.com/
http://mydomain.com/
https://mydomain.com:8080/https://mydomain.com/ http://mydomain.com/ http://mydomain.com/: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)
上面所有的URL都不会共享相同的存储。(web页面的注意路径不影响web存储)
-
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.
即使对于相同的源策略在不同的选项卡中打开的文档,会话存储也是不同的,所以在两个不同的选项卡中打开相同的web页面不能共享相同的会话存储。
-
Both local and session storage are also scoped by browser vendors. So storage data saved by IE cannot be read by Chrome or FF.
本地和会话存储也都由浏览器供应商确定。因此,IE保存的存储数据不能被Chrome或FF读取。
Hope this helps.
希望这个有帮助。
#4
24
The main difference between localStorage
and sessionStorage
is that sessionStorage
is unique per tab. If you close the tab the sessionStorage
gets deleted, localStorage
does not. Also you cannot communicate between tabs :)
localStorage和sessionStorage的主要区别在于,sessionStorage是每个选项卡唯一的。如果关闭选项卡,sessionStorage会被删除,localStorage则不会。也不能在选项卡之间进行通信。
Another subtle difference is that for example on Safari (8.0.3) localStorage
has a limit of 2551 k characters but sessionStorage
has unlimited storage
另一个细微的差别是,例如在Safari (8.0.3) localStorage中有2551 k字符的限制,但是sessionStorage有无限的存储空间。
On Chrome (v43) both localStorage
and sessionStorage
are limited to 5101 k characters (no difference between normal / private mode)
在Chrome (v43)上,localStorage和sessionStorage都限制在5101 k字符(正常/私有模式之间没有区别)
On Firefox both localStorage
and sessionStorage
are limited to 5120 k characters (no difference between normal / incognito mode)
在Firefox上,localStorage和sessionStorage被限制为5120k字符(正常/匿名模式之间没有区别)
No difference in speed whatsoever :)
速度无差异:)
There's also a problem with Mobile Safari and Mobile Chrome, Private Mode Safari & Chrome have a maximum space of 0KB
移动Safari和移动Chrome也有问题,私有模式Safari和Chrome的最大空间是0KB。
#5
10
Local storage can store upto 10mb offline data( in chrome 10 mb, in other browsers 5 mb), whereas session storage can store upto 5 mb data. But cookies can store only 4kb text data. See More Details Here
本地存储可以存储upto 10mb离线数据(在chrome 10mb中,在其他浏览器5 mb),而会话存储可以存储5 mb的数据。但是cookie只能存储4kb的文本数据。看到更多的细节
#6
9
performance wise, my (crude) measurements found no difference on 1000 writes and reads
性能方面,我的(粗略的)测量没有发现1000写和读的差异。
security wise, intuitively it would seem the localStore might be shut down before the sessionStore, but have no concrete evidence - maybe someone else does?
安全方面,直觉上,在sessionStore之前,localStore可能会被关闭,但是没有具体的证据——可能是其他人做的?
functional wise, concur with digitalFresh above
功能上的智慧,与上面的数字保持一致。
#7
9
sessionStorage is the same as localStorage, except that it stores the data for only one session, and it will be removed when the user closes the browser window that created it
sessionStorage与localStorage相同,只是它只存储一个会话的数据,当用户关闭创建它的浏览器窗口时,它将被删除。
#8
6
Ya session storage and local storage are same in behaviour except one that is local storage will store the data until and unless the user delete the cache and cookies and session storage data will retain in the system until we close the session i,e until we close the session storage created window.
丫会话存储和本地存储是相同的行为,除了一个本地存储将存储的数据,除非用户删除缓存和饼干和会话存储数据将保留在系统中,直到我们关闭会话我,直到我们关闭会话存储创建的窗口。
#9
5
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. (Of course it depends on what your goal is.)
在我看来,会话存储在本地存储上的优势在于,它在Firefox中具有无限的容量,而且不会比会话更持久。(当然这取决于你的目标是什么。)
#10
4
There is no difference between them extend Storage, but the sessionStorage for the session (tab or for the window) and localStorage exists for the domain until it is explicitly deleted (calling clear method or clearing browser cash).
它们之间没有区别扩展存储,但是会话的sessionStorage(选项卡或窗口)和localStorage存在于域,直到它被显式地删除(调用clear方法或清除浏览器现金)。
Read this article: http://fend-tricks.com/html5-web-storage/
读这篇文章:http://fend-tricks.com/html5-web-storage/
#1
541
localStorage
and sessionStorage
both extend Storage
. There is no difference between them except for the intended "non-persistence" of sessionStorage
.
localStorage和sessionStorage都可以扩展存储空间。它们之间并没有区别,除非是有意的sessionStorage的“非持久性”。
That is, the data stored in localStorage
persists until explicitly deleted. Changes made are saved and available for all current and future visits to the site.
也就是说,存储在localStorage中的数据一直存在,直到被显式删除。所做的更改保存并可用于所有当前和将来访问该站点的访问。
For sessionStorage
, changes are only available per window (or tab in browsers like Chrome and Firefox). Changes made are saved and available for the current page, as well as future visits to the site on the same window. Once the window is closed, the storage is deleted.
对于sessionStorage,更改只能在每个窗口中使用(或在Chrome和Firefox等浏览器中使用)。所做的更改保存并可用于当前页面,以及将来访问同一窗口的站点。一旦窗口关闭,存储将被删除。
#2
132
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 sessionStorage
over 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只能是可访问的,而创建它的窗口是打开的。localStorage一直持续到您删除它或用户删除它为止。假设您想要保存登录用户名和密码,出于安全考虑,您希望使用sessionStorageover localStorage。另一个人在以后访问他们的帐户。但是,如果您想要在他们的机器上保存用户的设置,您可能需要localStorage。总而言之:
localStorage
- use for long term use.sessionStorage
- use when you need to store somthing that changes or somthing temporary
localStorage -用于长期使用。sessionStorage——当您需要存储一些临时更改或临时的内容时使用。
#3
92
Few other points which might be helpful to understand differences between local and session storage
很少有其他的点可能有助于理解本地和会话存储之间的差异。
-
Both local storage and session storage are scoped to document origin, so
本地存储和会话存储都被限定为文档的来源。
https://mydomain.com/
http://mydomain.com/
https://mydomain.com:8080/https://mydomain.com/ http://mydomain.com/ http://mydomain.com/: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)
上面所有的URL都不会共享相同的存储。(web页面的注意路径不影响web存储)
-
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.
即使对于相同的源策略在不同的选项卡中打开的文档,会话存储也是不同的,所以在两个不同的选项卡中打开相同的web页面不能共享相同的会话存储。
-
Both local and session storage are also scoped by browser vendors. So storage data saved by IE cannot be read by Chrome or FF.
本地和会话存储也都由浏览器供应商确定。因此,IE保存的存储数据不能被Chrome或FF读取。
Hope this helps.
希望这个有帮助。
#4
24
The main difference between localStorage
and sessionStorage
is that sessionStorage
is unique per tab. If you close the tab the sessionStorage
gets deleted, localStorage
does not. Also you cannot communicate between tabs :)
localStorage和sessionStorage的主要区别在于,sessionStorage是每个选项卡唯一的。如果关闭选项卡,sessionStorage会被删除,localStorage则不会。也不能在选项卡之间进行通信。
Another subtle difference is that for example on Safari (8.0.3) localStorage
has a limit of 2551 k characters but sessionStorage
has unlimited storage
另一个细微的差别是,例如在Safari (8.0.3) localStorage中有2551 k字符的限制,但是sessionStorage有无限的存储空间。
On Chrome (v43) both localStorage
and sessionStorage
are limited to 5101 k characters (no difference between normal / private mode)
在Chrome (v43)上,localStorage和sessionStorage都限制在5101 k字符(正常/私有模式之间没有区别)
On Firefox both localStorage
and sessionStorage
are limited to 5120 k characters (no difference between normal / incognito mode)
在Firefox上,localStorage和sessionStorage被限制为5120k字符(正常/匿名模式之间没有区别)
No difference in speed whatsoever :)
速度无差异:)
There's also a problem with Mobile Safari and Mobile Chrome, Private Mode Safari & Chrome have a maximum space of 0KB
移动Safari和移动Chrome也有问题,私有模式Safari和Chrome的最大空间是0KB。
#5
10
Local storage can store upto 10mb offline data( in chrome 10 mb, in other browsers 5 mb), whereas session storage can store upto 5 mb data. But cookies can store only 4kb text data. See More Details Here
本地存储可以存储upto 10mb离线数据(在chrome 10mb中,在其他浏览器5 mb),而会话存储可以存储5 mb的数据。但是cookie只能存储4kb的文本数据。看到更多的细节
#6
9
performance wise, my (crude) measurements found no difference on 1000 writes and reads
性能方面,我的(粗略的)测量没有发现1000写和读的差异。
security wise, intuitively it would seem the localStore might be shut down before the sessionStore, but have no concrete evidence - maybe someone else does?
安全方面,直觉上,在sessionStore之前,localStore可能会被关闭,但是没有具体的证据——可能是其他人做的?
functional wise, concur with digitalFresh above
功能上的智慧,与上面的数字保持一致。
#7
9
sessionStorage is the same as localStorage, except that it stores the data for only one session, and it will be removed when the user closes the browser window that created it
sessionStorage与localStorage相同,只是它只存储一个会话的数据,当用户关闭创建它的浏览器窗口时,它将被删除。
#8
6
Ya session storage and local storage are same in behaviour except one that is local storage will store the data until and unless the user delete the cache and cookies and session storage data will retain in the system until we close the session i,e until we close the session storage created window.
丫会话存储和本地存储是相同的行为,除了一个本地存储将存储的数据,除非用户删除缓存和饼干和会话存储数据将保留在系统中,直到我们关闭会话我,直到我们关闭会话存储创建的窗口。
#9
5
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. (Of course it depends on what your goal is.)
在我看来,会话存储在本地存储上的优势在于,它在Firefox中具有无限的容量,而且不会比会话更持久。(当然这取决于你的目标是什么。)
#10
4
There is no difference between them extend Storage, but the sessionStorage for the session (tab or for the window) and localStorage exists for the domain until it is explicitly deleted (calling clear method or clearing browser cash).
它们之间没有区别扩展存储,但是会话的sessionStorage(选项卡或窗口)和localStorage存在于域,直到它被显式地删除(调用clear方法或清除浏览器现金)。
Read this article: http://fend-tricks.com/html5-web-storage/
读这篇文章:http://fend-tricks.com/html5-web-storage/