本地存储Vs饼干 - 性能 [英] Localstorage Vs Cookies - Performance

查看:143
本文介绍了本地存储Vs饼干 - 性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Cookie是服务器端,且Localstorage是客户端,这是用户检索速度最快的(参考本地存储vs Cookie

Since cookies are server-side and Localstorage is client-side, which is the fastest for the user to retrieve? (ref. Local Storage vs Cookies)

我假设客户端的计算机速度较慢,

I assume if the client's machine is slow, then cookies are faster? Or that makes no diffrence?

我使用localstorage&一个项目的cookie和二者都使用jQuery检索。这意味着,jquery必须加载,然后正在检索数据。

I am using both localstorage & cookies for a project and both are retrieved using jQuery. That means, jquery has to get loaded, then the data is being retrieved.

如何提高速度?我不知道两者如何工作。例如,有人说,一旦HTML尝试加载样式和js文件之前,以及其他人说DOM准备好时,正在检索Cookie。

How can I make this faster? I don't know how both work. For example, some say that Cookies are being retrieved once the HTML is trying to load before the style's and js files and others say when DOM is ready.

有人知道准确

谢谢

推荐答案


由于Cookie是服务器端的,而Localstorage是客户端的,这是用户检索的最快的?

Since cookies are server-side and Localstorage is client-side, which is the fastest for the user to retrieve?

你开始使用不正确的假设。 Cookie也存储在客户端。

You're starting off with an incorrect assumption. Cookies are stored client-side as well. Both localStorage and cookies are stored client side.

不同之处在于,可以从服务器端操作cookies

The difference however, and that cookies can be set, manipulated from the server side. localStorage is only workable from the client side.


我假设客户端的机器速度很慢,那么Cookie是更快?

I assume if the client's machine is slow, then cookies are faster? Or that makes no diffrence [sic]?

他们是这样的轻量级操作,我不担心速度。

They are such lightweight operations I wouldn't worry about speed.

两者之间的性能不是选择一个的因素。这是你的需求。

Performance between the two is not a factor for choosing one. It's what are your needs.

Cookie:


  1. 时间。

  2. 可以访问和操纵服务器端。

  3. 通常限制为几千字节,具体取决于浏览器。

  1. Have worked in browsers for a long time. Every modern, and not so modern, browser support cookies.
  2. Can be accessed and manipulated server side.
  3. Are typically limited to a few kilobytes, depending on browser.

localStorage:

localStorage:


  1. 是一个相对较新的概念。并非所有浏览器都支持它。例如IE 6,7,而且运气不好。

  2. 从服务器端无法访问。

  3. 您可以使用存储在localStorage中的数据对服务器回送AJAX。
  4. 有一个W3C 建议可以存储5 MB。
  1. Is a relatively new concept. Not all browsers support it. IE 6, 7 for example, and you're out of luck.
  2. Is inaccessible from the server side. You could make an AJAX call back to the server with data that is stored in localStorage.
  3. Have a W3C recommendation of being able to store 5 MB.




如何更快地完成?

How can I make this faster?

我不认为任何一个都可以直接引入性能问题。其他问题,如等待DOM处于就绪状态,等待脚本文件加载;等等可以引入减速。

I don't think either one can directly introduce a performance problem. Other problems, like waiting for the DOM to be in ready state, waiting for script files to load; etc. can introduce slowdowns.

这篇关于本地存储Vs饼干 - 性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆