what happens when cookies file exceeds maximum size?
Asked Answered
W

3

31

What really happens when cookies file exceeds maximum size?

Woodyard answered 20/10, 2009 at 16:32 Comment(2)
var i = 0; while( true ) { i++; document.cookie = i + "=" + i + ";" + document.cookie; } Try it out.Filibertofilibuster
worth pointing out that the above comment will result in an infinite loop, since browsers tend to discard old cookies when there are more than 20-ish of them for the same domain... also, it does not answer the question of a maximum file size, only maximum number of cookie files per domainArmhole
K
28

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.

Kelton answered 20/10, 2009 at 17:1 Comment(0)
A
10

The file is truncated to the maximum length.

Amboceptor answered 21/2, 2012 at 7:6 Comment(0)
N
6

I think that would be browser dependent, since RFC2965 does not define a maximum size for cookies or any standard behavior for when the maximum is exceeded.

Nolly answered 20/10, 2009 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.