Summary of the number and size limits of cookies in each Browser

Source: Internet
Author: User
Tags set cookie

Microsoft said that Internet Explorer 8 has increased the number of cookies that can be saved in each domain to 50, but I found that IE7 also allows 50 cookies to be saved in each domain. Of course, this may be because a system patch is added, rather than the browser version, but it still exceeds the 20 limit.
Firefox allows 50 cookies for each domain.
Opera allows 50 cookies for each domain.

Safari/WebKit is the most interesting one, because it does not seem to have obvious restrictions until Safari 3.1. I tested setting 10,000 cookies. As a result, all these cookies are successfully set and sent along with the cookie header. However, the problem is that the size of the header exceeds the limit, which causes the server to be unable to handle the problem and causes an error.

Therefore, we previously thought that the browser restricts the number of cookies in each domain to 20. Another interesting phenomenon of inconsistency is: how does the browser respond when too many cookies are set. In addition to the exception in Safari, all others have set the maximum number of cookies. There are two methods:
When the number of cookies reaches the limit, the latest least-used algorithm (LRU) automatically removes the oldest cookie, so that you can free up space for the latest cookie. Internet Explorer and Opera use this method.
Firefox seems a bit strange: It seems that it randomly decides to save the cookie, although the last cookie will always be saved. It does not seem to be clear what rules it follows. What should I do? (The takeaway? In Firefox, do not exceed the cookie limit.
Different browsers have different cookie sizes. This is a bit difficult to understand, but here are some of my test results:
Firefox and Safari allow a cookie to contain a maximum of 4097 characters, that is, the name and value of the cookie can contain a total of 4096 characters and an equal sign (= ).
Opera allows a cookie to contain a maximum of 4096 characters, including the name, value, and equal sign (= ).
Internet Explorer allows cookies to contain a maximum of 4095 characters, including names, values, and equal signs (= ).

Note that all tests here use single-byte characters, and the length of double-byte characters is naturally recorded as 2. In all browsers, any cookie whose length exceeds the limit will be ignored and will never be set.
After these tests, I came to the conclusion that the traditional understanding of cookie restrictions (mostly from the original cookie Specification) is no longer correct. We should be very cautious when using cookies and always use them to a minimum.

I. The Browser allows the number of cookies contained in each domain name:

Microsoft pointed out that InternetExplorer8 adds a cookie limit of 50 for each domain name, But IE7 also seems to allow 50 cookies for each domain name.

Firefox has a maximum of 50 cookies for each domain name.

Opera has a maximum of 30 cookies for each domain name.

Safari/WebKit seems to have no cookie restrictions. However, if there are many cookies, the header size will exceed the server's processing limit, which may cause errors.

Note: "Each domain name has 20 cookies" is no longer correct!

2. When many cookies are set, how does the browser respond.

Besides Safari (you can set all cookies regardless of the number of cookies), there are two methods:

Least recently used (leastrecentlyused (LRU) method: When the Cookie has reached the limit, the oldest Cookie is automatically kicked out to make some space for the latest Cookie. InternetExplorer and Opera use this method.

Firefox is unique: although the last set Cookie is always retained, it seems that it randomly determines which cookies are retained. There seems to be no plan (we recommend that you do not exceed the Cookie limit in Firefox ).

3. Different browsers have different cookie sizes:

Firefox and Safari allow cookies to contain up to 4097 bytes, including names, values, and equal signs.

Opera allows cookies to contain up to 4096 bytes, including name, value, and equal sign.

InternetExplorer allows cookies to contain up to 4095 bytes, including name, value, and equal sign.

Note: Multi-byte characters are calculated as two bytes. In all browsers, any cookie that exceeds the limit is ignored and never set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.