简体   繁体   English

使用sessionStorage有什么好处?

[英]What are the benefits of using sessionStorage?

Just wondering what are the actual benefits of using HTML5's sessionStorage when storing HTML content to be used in a Javascript carousel? 只是想知道在存储要在Javascript轮播中使用的HTML内容时使用HTML5的sessionStorage的实际好处是什么?

Is it performance related? 它与性能有关吗? Load Times? 加载时间? Bandwidth? 带宽?

Yes you'll use less bandwidth, it'll be better for performance because you can store information in your browser up to 5Mb . 是的,您将使用更少的带宽,它会更好地提高性能,因为您可以在浏览器中存储最多5Mb的信息 It's much more than with cookie. 它不仅仅是使用cookie。

For instance to set an item in the storage you can do: 例如,要在存储中设置项目,您可以执行以下操作:

sessionStorage.setItem("name1", "value1");

and to get the item 并获得该项目

sessionStorage.getItem("name1");

The sessionStorage is relative to each subdomain/domain. sessionStorage与每个子域/域相关。

Yes. 是。 sessionStorage stores much more information than cookies can, and it is easier to access as well. sessionStorage存储的信息比cookie更多,而且访问也更容易。

By storing data you need to access again locally, you avoid (or minimize) ajax calls, and in turn server and database loads. 通过存储您需要在本地再次访问的数据,可以避免(或最小化)ajax调用,进而避免服务器和数据库负载。

This will result in faster page loads (as you will not need to wait for the server to provide the data), and bandwidth (as you have minimized communication with the server). 这将导致更快的页面加载(因为您不需要等待服务器提供数据)和带宽(因为您已经最小化了与服务器的通信)。

Theoretically (and probably actually in most cases), faster load time, as it is almost like the images are already cached (loading from the user rather than the server). 从理论上讲(实际上可能在大多数情况下),加载时间更快,因为它几乎就像图像已经被缓存(从用户而不是服务器加载)。 I don't know much about it, but had looked into whether it would help as a storage for images on https connections. 我不太了解它,但已经研究过它是否有助于作为https连接上的图像存储。 It did not help there (and in fact, may have made it worse). 它没有帮助(事实上,可能会使情况变得更糟)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM