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

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

问题描述

我正在学习 cookie,我想知道在编写依赖 cookie 来存储状态的 Web 应用程序时浏览器是否支持.

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

  • 对于每个域/网站,可以向浏览器发送多少个 cookie,大小是多少?

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

如果发送和存储多个 cookie,是否会影响性能?

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.

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

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.

第三,如果您确实需要担心,请知道有两种可能的 cookie 标头.这些 cookie 标头的大小由浏览器软件限制决定.

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.

设计讨论

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

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.

性能

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

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天全站免登陆