What really happens when cookies file exceeds maximum size?
The 4K is the maximum size for the entire cookie, including name, value, expiry date etc. To support most browsers, it is suggested to keep the name under 4000 bytes, and the overall cookie size under 4093 bytes.
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.
The file is truncated to the maximum length.
The typical behavior of most browsers, to my knowledge, is to simply truncate the oldest data that does not fit.
For example, create cookies 1 through 9. When creating cookie 10 and the data size is going to overflow, cookie 1 is simply discarded.
In general practice, if you are worried about bumping into the limit and loosing cookies to overflow, it is probably time to rethink your strategy of what you are storing and start caching the data server-side and limiting the cookie to a value to access the cached data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With