Browser Cookie Limits

I have a requirement to store a large amount of data in cookies, to figure out if it will work here are my tests.

If all you care about is the conclusion, well here it is: If you want to support most browsers, then don't exceed 50 cookies per domain, and don't exceed 4093 bytes per domain (i.e. total size of all cookies <= 4093 bytes)

Your Browser Test Results

About The Tests

Max Cookie Count Per Domain is calculated by adding cookies until the number of cookies saved stops increasing.

Max Cookie Size Per Cookie is calculated by increasing the cookies value one character at a time, until the saved value is truncated.

Max Cookie Size Per Domain is guessed by adding cookies of maximum size, until no more cookies can be added. Hence, the actual limit may be more than the guessed limit. Guessed Limit <= Actual Limit < Guessed Limit + Max CookieSize

Manually Execute Tests

1. Max Cookies Test

Each cookie will be filled with the following character, repeated the specified number of times.
Character: Repeat Character Times:

Some Interesting Things

Typically, the following are allowed: * Given 20 cookies of max size 4096 = 81920 bytes.

IE (and Opera) introduces a new limit, max bytes per domain

A few notes about cookies:

Alternatives

Limits Per Browser

After testing a few browsers myself, and using Browser Shots I have compiled the following list:
Browser Max Cookies Max Size Per Cookie Max Size Per Domain1 Usage2
Chrome 4
Chrome 5-7704096 bytesNA
Chrome 8-25*1804096 bytesNA48.4%
* Checked on 8/10/12/13/14/15/17/25. Unverified on 9/11/16/18-24, just assumed
FireFox 2/3.6.6504097 charactersNA1.3% (versions before 3.6)
FireFox 3.6.13-19*1504097 charactersNA29.8%
* verified on 3.6.13/4/8/9/10/14/19. unverified 5-8/11-13/15-18, just assumed
IE 6 unpatched204096 characters4096 characters
IE 6504096 characters4096 characters0.3% WTF
IE 7 unpatched204095 characters4095 characters
IE 7504095 characters4095 characters1.0%
IE 8/9/10505117 characters10234 characters13.1%
Opera 8/9/10304096 bytes4096 bytes
Opera 11604096 bytes4096 bytes0.1%
Opera 12605117 bytes12093 bytes1.1%
Safari 3
Safari 40.1%
Safari 56004096 bytes4096 bytes1.4%
Safari 62.7%
Safari on mac360044093 bytes4most likely 4093 bytes4
Android 2.1/2.3.4504096 bytesNA
Safari Mobile 5.160054093 bytes54093 bytes
1 NA means there is no limit other than Max Cookies * Max Size Per Cookie
2 From January 2013 W3 Schools Browser Statistics, except Firefox I used Dec 2012.
3 Lu pointed out Safari on mac is different to windows. It appears to have no limit. I will investigate when I get more time.
4 Deeman has shared these Safari Mac results in the comments below.
5 Safari on my iPad 3 iOS 5.1 has a limit of 4096 bytes, but an overhead of 3 bytes per cookie. Hence the max for 1 cookie is 4093, and I can fit 512 cookie of 5 bytes as 512*(5+3)=4096.

Conclusion

If you want to support most browsers, then don't exceed 50 cookies per domain, and don't exceed 4093** bytes per domain (i.e. total size of all cookies <= 4093 bytes). Plus it appears the 600 count limit is really the 4096 limit being enforced.

** I previously said 4095 bytes to account for IE7, but now iPad 3 appears to come in a little lower.

By Iain Roberts. Created 02 March 2011. Last Updated 05 March 2013.

Updates

Contact Me

Find anything wrong? Is there a better way? Comment below or send me an email to
blog comments powered by Disqus