Reputation: 4767
Suppose that you have to set 12 cookies, would it be better to store all of their values in a single "big" cookie or store each value on its own cookie? I want to know if that improves website speed.
Thanks.
Upvotes: 0
Views: 312
Reputation: 192
I think the maximium size of a cookie is about 4k. If you need to store more data than that, then you're better off using several cookies.
i don't think there will be a big performance issue using multiple cookies. in my opinion, it may be more efficient to store each piece of data in its own cookie rather than parsing through a bogger cookie for each "crum" of data each time you need it.
Hope this helps!
Upvotes: 4
Reputation: 180085
You could always use sessions, which store the session ID in a cookie and store everything else in your database/filesystem referenced against that session ID. That way, the data is not sent on every request, only the session ID is.
Upvotes: 0
Reputation: 46410
If there is any doubt the best thing to do is try it both ways and use a free utility like tcptrace to show you how much bandwidth each method consumes. That should definitively give you your answer, because if there is a difference in performance between the two methods you've proposed, it is probably due to bandwidth consumption.
Upvotes: 1
Reputation: 63465
The number of cookies is hardly going to affect speed in any meaningful way since either they'll all be sent through the request separated by Cookie:
headers, or you'll have one Cookie:
header with data concatenated in your own way. Technically, the "faster" way would be to use one cookie.
In reality, this is a micro-optimization and you shouldn't worry about it.
Upvotes: 2