Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the maximum size of a web browser's cookie's key?

What is the maximum size of a web browser's cookie's key?

I know the maximum size of a cookie is 4KB, but does the key have a limitation as well?

like image 377
user77480 Avatar asked Mar 12 '09 23:03

user77480


People also ask

What is the maximum size of cookie 4 KB?

The max size of a cookie is 4096 bytes.

What is the maximum size of a cookie in KB?

No more than 50 cookies per domain, with a maximum of 4 KB per cookie (or even 4 KB in total, see Iain's answer).

What is the maximum size of cookie 4KB 4mb 4 bytes 40kb?

Correct Option: CThe 4K is the maximum size for the entire cookie, including name, value, expiry date etc.

Can we increase cookie size?

In a modern browser you have better client-side storage alternatives. It is not a good idea to add an overhead of more than 4KB to every HTTP request. You can have a maximum of 50 cookies per domain and a total of 4KB. i.e. you can have 1 cookie of 4096 bytes, or 2 cookies with 2048, and so on.


2 Answers

The 4K limit you read about is for the entire cookie, including name, value, expiry date etc. If you want to support most browsers, I suggest keeping the name under 4000 bytes, and the overall cookie size under 4093 bytes.

One thing to be careful of: if the name is too big you cannot delete the cookie (at least in JavaScript). A cookie is deleted by updating it and setting it to expire. If the name is too big, say 4090 bytes, I found that I could not set an expiry date. I only looked into this out of interest, not that I plan to have a name that big.

To read more about it, here are the "Browser Cookie Limits" for common browsers.


While on the subject, if you want to support most browsers, then do not exceed 50 cookies per domain, and 4093 bytes per domain. That is, the size of all cookies should not exceed 4093 bytes.

This means you can have 1 cookie of 4093 bytes, or 2 cookies of 2045 bytes, etc.


I used to say 4095 bytes due to IE7, however now Mobile Safari comes in with 4096 bytes with a 3 byte overhead per cookie, so 4093 bytes max.

like image 86
Iain Avatar answered Oct 08 '22 15:10

Iain


Actually, RFC 2965, the document that defines how cookies work, specifies that there should be no maximum length of a cookie's key or value size, and encourages implementations to support arbitrarily large cookies. Each browser's implementation maximum will necessarily be different, so consult individual browser documentation.

See section 5.3, "Implementation Limits", in the RFC.

like image 38
John Feminella Avatar answered Oct 08 '22 15:10

John Feminella