除了非持久化和仅作用于当前窗口之外,会话存储相对于本地存储是否有任何好处(性能,数据访问等)?


当前回答

在我看来,会话存储相对于本地存储的优势在于,它在Firefox中具有无限的容量,并且不会持续比会话更长的时间。(当然这取决于你的目标是什么。)

其他回答

本地存储:保存没有过期日期的用户信息数据,当用户关闭浏览器窗口时,这些数据不会被删除,它将在天,周,月和年可用。

//Set the value in a local storage object
localStorage.setItem('name', myName);

//Get the value from storage object
localStorage.getItem('name');

//Delete the value from local storage object
localStorage.removeItem(name);//Delete specifice obeject from local storege
localStorage.clear();//Delete all from local storege

会话存储:它与本地存储日期相同,只是当web用户关闭浏览器窗口时,它会删除所有窗口。

//set the value to a object in session storege
sessionStorage.myNameInSession = "Krishna";

阅读更多点击

localStorage和sessionStorage都扩展了Storage。除了sessionStorage的“非持久性”之外,它们之间没有任何区别。

也就是说,存储在localStorage中的数据将一直存在,直到显式删除为止。所做的更改将被保存,并可用于当前和将来对站点的所有访问。

对于sessionStorage,更改仅适用于每个选项卡。所做的更改将被保存,并可用于该选项卡中的当前页面,直到关闭该选项卡为止。一旦关闭,存储的数据就会被删除。

其他几点可能有助于理解本地存储和会话存储之间的区别

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.

性能方面,我的(粗略的)测量在1000次写入和读取时没有发现差异

安全方面,从直觉上看,localStore可能会在sessionStore之前关闭,但没有具体的证据-也许其他人会?

功能方面,与digitalFresh一致

sessionStorage与localStorage相同,只是它只存储一个会话的数据,并且当用户关闭创建它的浏览器窗口时,它将被删除。