Cookie的最大大小是多少,每个网站的浏览器中可以存储多少? [英] What is the maximum size of a cookie, and how many can be stored in a browser for each web site?

查看:2491
本文介绍了Cookie的最大大小是多少,每个网站的浏览器中可以存储多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习cookies,在编写依赖于cookies的网络应用程序来存储状态时,我不知道浏览器的支持情况。





  • 如果发送和存储了多个Cookie,则每个域/网站可以向浏览器发送多少个Cookie,是否会影响性能?



解决方案

担心这个问题。有AMPLE房间可以序列化大量的标识符。



其次,它不是由 web-server 存储,而是由 web-domain - 例如, www.google.com ,而不是服务Google网域的不同物理服务器的100个。



第三,如果您确实担心有两个可能的Cookie标头。这些Cookie标头的大小由浏览器软件限制确定。



设计讨论



您不想使用Cookie标头的是发送客户端会话的详细信息。例如,如果您正在构建电子邮件前端,请不要尝试填充客户端正在输入Cookie的电子邮件。相反,您会向客户端发送表示其身份+会话的cookie:您将根据此身份存储所有会话数据。你可以存储几十个标识符(4-16字节)每个cookie头,没有人需要超过4这些。 Cookie数据(作为整数)往往会被编码为 base64 ,这会增加字节计数



您的浏览器会将大量标头传送至网页,服务器。 cookie只是另一个100-1000字节(大多接近100)。在两种极端情况下,将这些发送到Web服务器只需要一小部分时间 - 当放置到上下文中时。您应该记住,网络建立在基于文本的协议上。


I am learning about cookies, and I wonder about browser support when writing web applications that rely on cookies to store state.

  • For each domain/web site, how many cookies may be sent to a browser, and of what size?

  • If multiple cookies are sent and stored, does that affect performance?

解决方案

Firstly, I suggest you don't worry about this issue. There is AMPLE room to serialize tons of identifiers to.

Secondly it's not stored by web-server but by web-domain — e.g., www.google.com and not the 100's of different physical servers that serve the Google domain.

Thirdly if you do have to worry know that there are two possible cookie headers. The sizes of these cookie headers are determined by the browser software limits.

Design Discussion

What you don't want to use the cookie header for is sending details about a client's session. E.g., don't try to stuff the email a client is typing into a cookie if you are building an email front-end. Instead you would send the client a cookie that represents his identity+session: you store all sessions data against this identity. You can store tens of identifiers (4–16 bytes) per cookie header and no one needs more than say 4 of these. The cookies data (as an integer) tends to be encoded to base64 which increases the byte-count.

Performance

Your browser sends a plethora of headers to a web-server. The cookie is just another 100-1000 bytes (mostly closer to 100). At both extremes it takes only a fraction of time to send these to the web-server — when placed into context of course. You should keep in mind that the web is built on text based protocols.

这篇关于Cookie的最大大小是多少,每个网站的浏览器中可以存储多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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