Question

I could not find an answer for this question online. Is it good practice to combine multiple cookies into one single cookie to reduce http-requests? And if so, how should I do this. Should I use JSON or are there better options?

Cheers!

Was it helpful?

Solution

If you combine several cookies into a single cookie, you do not reduce the number of http-requests, but only the size of the Cookie: header for every request. On the other hand if some of the Cookies would only be send for some path and not others, combining them into one might actually make the header longer, as the information from all cookies are send to every page, as a single cookie necessarily has to be defined to use the shortest of all pathes of the combined cookies.

Anyway, here is the cookie header send by the browser when you have three cookies set:

Cookie: cookie1=value1; cookie2=value2; cookie3=value3

As you can see, this does not even use separate headers; if you want to send the same information in one cookie, it will not save much space. If you really worry about bandwidth you might make the names of your cookies shorter, which will nearly achieve the same effect, but honestly I do not think this is worth any effort - there are other things consuming much more bandwidth than cookies, so there is little to win by optimizing there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top