views:

111

answers:

4

Hi,

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.

+2  A: 

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.

John Rasch
+1  A: 

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.

Jeremy
A: 

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.

ceejayoz
+3  A: 

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!

Andres