Javascript 现代浏览器中当前的 cookie 限制是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5381526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 16:57:20  来源:igfitidea点击:

What are the current cookie limits in modern browsers?

javascriptbrowsercookiescross-browserlimit

提问by GreyCat

What are the generic cookie limits for modern browsers, as of 2011? I'm particularly interested in:

截至 2011 年,现代浏览器的通用 cookie 限制是什么?我特别感兴趣的是:

  • Max size of a single cookie
  • Max number of cookies per host/domain name + path
  • Max number of cookies per host/domain name
  • Max number / max total size of all cookies in a given browser
  • 单个 cookie 的最大大小
  • 每个主机/域名 + 路径的最大 cookie 数
  • 每个主机/域名的最大 cookie 数
  • 给定浏览器中所有 cookie 的最大数量/最大总大小

I'm aware of RFC 2109that specifies:

我知道RFC 2109规定:

  • at least 300 cookies
  • at least 4096 bytes per cookie (as measured by the size of the characters that comprise the cookie non-terminal in the syntax description of the Set-Cookie header)
  • at least 20 cookies per unique host or domain name
  • 至少 300 个饼干
  • 每个 cookie 至少 4096 字节(根据 Set-Cookie 标头的语法描述中构成 cookie 非终结符的字符的大小来衡量)
  • 每个唯一的主机名或域名至少有 20 个 cookie

but what are real-world specs?

但什么是现实世界的规格?

回答by Please treat your mods well.

Here's a handy tool to test it: http://browsercookielimits.squawky.net/

这是一个方便的测试工具:http: //browsercookielimits.squawky.net/

It reveals quite a lot about the internal details regarding cookies. Click "Run Tests for Current Browser" for the results (it only takes a moment).

它揭示了很多关于 cookie 的内部细节。单击“为当前浏览器运行测试”以获取结果(只需片刻)。

For example, I ran all tests for Google Chrome 10.0.648.134 beta:

例如,我为 Google Chrome 10.0.648.134 beta 运行了所有测试:

22:23:46.639: Starting
22:23:47.345: Count: Max Cookie count with Character Length 3 and character "1": 180
22:23:50.131: Size: Max Cookie Character Length using character "1": 4096
22:23:52.347: Count: Max Cookie count with Character Length 4096 and character "1": 180
22:23:54.517: Size: Max Cookie Character Length using character "?": 2049
22:23:57.450: Count: Max Cookie count with Character Length 2049 and character "?": 180
22:23:59.41: Count: Max Cookie count with Character Length 100 and character "1": 180
22:24:0.535: Count: Max Cookie count with Character Length 10 and character "1": 180
22:24:2.88: Count: Max Cookie count with Character Length 5 and character "1": 180
22:24:2.886: Guessing Max Cookie Count Per Domain: 180
22:24:2.887: Guessing Max Cookie Size Per Cookie: 4096 bytes
22:24:2.887: Guessing Max Cookie Size Per Domain: NA


This answer is pretty old, but I just checked results for the latest Chrome version, and they're essentially the same. Edit: updated the answers for Chrome 54.0.2840.98 (64-bit).

这个答案很旧,但我只是检查了最新 Chrome 版本的结果,它们基本上是一样的。编辑:更新了 Chrome 54.0.2840.98(64 位)的答案。

回答by Webveloper

According to this thread, Firefox 3.5 raised the total limit for all hoststo 3000, and Chrome followed their lead. All I've found for IE is "at least 300".

根据该线程,Firefox 3.5 将所有主机的总限制提高到 3000,Chrome紧随其后。我发现的所有 IE 都是“至少 300”。

Also, while regular Safari appears to be unlimited, Mobile Safari (iPod Touch 2G) has a limit of 50 cookies per host, as does Android Browser (Android 2.2).

此外,虽然常规 Safari 似乎不受限制,但 Mobile Safari (iPod Touch 2G)和 Android 浏览器 (Android 2.2) 一样,每个主机的cookie 限制为 50

回答by Skizz

You may also want to take a look at javascript for Client Side Storage, it's a feature of HTML5 that allows several Megabytes of data to be kept unseen on a visitors PC.

您可能还想看看用于客户端存储的 javascript,它是 HTML5 的一项功能,允许在访问者 PC 上保持几兆字节的数据不可见。

Several variants exist, here's one with good documentation http://www.jstorage.info/

存在多种变体,这里有一个带有良好文档的变体http://www.jstorage.info/

Aside from Opera 10.10 and Safari-3 all mainstream browsers including IE6 support the feature. Though IE6 can only store 128kb as opposed to the 5 to 10 Mbytes that the more recent offerings can. Of course how often older versions of Opera and Safari show up in the visitor logs varies with each site so may not be ideal for all.

除了 Opera 10.10 和 Safari-3,包括 IE6 在内的所有主流浏览器都支持该功能。尽管 IE6 只能存储 128kb,而最近的产品可以存储 5 到 10 MB。当然,旧版本的 Opera 和 Safari 出现在访问者日志中的频率因每个站点而异,因此可能并不适合所有人。

回答by Pascal Pixel Rigaux

In Firefox >= 63, the max number of cookies per domain is 180, cf pref "network.cookie.maxPerHost". When it reaches the limit, it will drop stale cookies, then drop non secure cookies. If nothing works, it will simply refuse the cookie (cf netwerk/cookie/nsCookieService.cpp)

在 Firefox >= 63 中,每个域的最大 cookie 数为180,参见首选项“network.cookie.maxPerHost”。当它达到限制时,它会丢弃过时的 cookie,然后丢弃非安全 cookie。如果没有任何效果,它将简单地拒绝 cookie (cf netwerk/cookie/nsCookieService.cpp)