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?
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.
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.
You can also use web storage too if the app specs allows you that (it has support for IE8+).
It has 5M (most browsers) or 10M (IE) of memory at its disposal.
"Web Storage (Second Edition)" is the API and "HTML5 Local Storage" is a quick start.
链接地址: http://www.djcxy.com/p/71438.html上一篇: 在休息收藏中寻呼