简体   繁体   English

主要浏览器允许的 cookie 数量和大小是多少?

[英]What is the number and size of cookies allowed by major browsers?

Just wondering what is the size and number of cookies allowed by IE, FF, Chrome, and Safari.只是想知道 IE、FF、Chrome 和 Safari 允许的 cookie 大小和数量是多少。 What is the number allowed per host and the size of each cookie?每个主机允许的数量和每个 cookie 的大小是多少? Also what would happen if you try to store cookie larger than the max size using Javascript?如果您尝试使用 Javascript 存储大于最大大小的 cookie 会发生什么?

It varies from browser to browser.它因浏览器而异。 The biggest limitation is IE6 which can only accept 20 domain cookies (all other modern browsers [FF3+, IE7/8, Safair 4/5, Chrome] can accept much much more).最大的限制是 IE6,它只能接受 20 个域 cookie(所有其他现代浏览器 [FF3+、IE7/8、Safair 4/5、Chrome] 可以接受更多)。 Once IE6 reaches it's 20 cookie limit, it randomly overwrites an older cookie, which is a major concern since you'll never know which one got removed.一旦 IE6 达到 20 个 cookie 的限制,它就会随机覆盖一个旧的 cookie,这是一个主要问题,因为您永远不会知道哪个被删除了。

If you like the run some specific tests -- visit this blog post and experiment with the authors test scripts.如果您喜欢运行一些特定的测试——请访问此博客文章并尝试使用作者的测试脚本。

http://www.ghacks.net/2008/08/16/browser-cookie-limits/ http://www.ghacks.net/2008/08/16/browser-cookie-limits/

Hope that helps.希望有帮助。

AFAIK the number of cookies you can set is 20 per domain or 300 maximum and each cookie across the board is generally capped at a 4k limit. AFAIK 您可以设置的 cookie 数量是每个域 20 个或最多 300 个,并且每个 cookie 的上限通常为 4k。

The RFC for cookies (section 6.3) has most of the information you want to find. cookieRFC (第 6.3 节)包含您想要查找的大部分信息。

As far as setting a cookie larger than the recommended size is concerned, I would suggest that some browsers will handle that differently, but taking the lowest-common denominator into consideration (IE6), I'd suggest you consider different forms of data persistence if you have that much data you need to store.至于设置大于推荐大小的 cookie,我建议某些浏览器会以不同的方式处理,但考虑到最低公分母(IE6),我建议您考虑不同形式的数据持久性,如果你有那么多需要存储的数据。

I looked into this today, if you want to support most browsers, then don't exceed 30 cookies per domain, and don't exceed 4095 bytes per domain (ie total size of all cookies <= 4095 bytes).我今天研究了这个,如果你想支持大多数浏览器,那么每个域不要超过 30 个 cookie,每个域不要超过 4095 个字节(即所有 cookie 的总大小 <= 4095 个字节)。

As for what happens when you exceed the limit, that depends on each browser and which limit you exceed.至于超出限制会发生什么,这取决于每个浏览器以及您超出的限制。 For example, in Chrome 8, when I add cookie 181, 20 cookies get deleted.例如,在 Chrome 8 中,当我添加 cookie 181 时,会删除 20 个 cookie。 Also in chrome 8, when I add a cookie with 5000 bytes, it gets truncated down to 4096 bytes.同样在 chrome 8 中,当我添加一个 5000 字节的 cookie 时,它​​会被截断为 4096 字节。 I suspect truncating is the standard way to handle over sized cookies.我怀疑截断是处理超大 cookie 的标准方法。

To read more about it here is my test page and results .在这里阅读更多关于它的信息是我的测试页和结果

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

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