?
Solved

Cookies: Key/Value pairs vs separate cookies

Posted on 2011-04-28
10
Medium Priority
?
491 Views
Last Modified: 2012-08-14
Can anyone tell me what the pros/cons are of using a single cookie with multiple key/value pairs vs using multiple cookies with a single value? I'm wondering if there are performance benefits or issues, or other programming pros/cons for one or the other.
0
Comment
Question by:nzinsli
  • 4
  • 3
  • 3
10 Comments
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 35483381
I don't think there's a performance difference.  The only issue I can think of is keeping track of the different names.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1000 total points
ID: 35483389
There are a couple of reasons to use subkeys instead of separate cookies. Obviously, it is tidy to put related or similar information into a single cookie. In addition, because all the information is in a single cookie, cookie attributes such as expiration apply to all the information. (Conversely, of course, if you want to assign different expiration dates to different types of information, you should store the information in separate cookies.)

A cookie with subkeys also helps you keep cookie size down. As noted earlier under Cookie Limitations, cookies are limited to 4096 bytes and you can't store more than 20 cookies per site. By using a single cookie with subkeys, you use up fewer of those 20 cookies your site is allotted. In addition, a single cookie takes up about 50 characters for overhead (expiration information, and so on), plus the length of the value that you store in it, all of which counts toward the 4K limit. If you store five subkeys instead of five separate cookies, you save the overhead of the separate cookies and can save around 200 bytes.



http://msdn.microsoft.com/en-us/library/aa289495(v=vs.71).aspx#vbtchaspnetcookies101anchor6

0
 

Author Comment

by:nzinsli
ID: 35483431
Is the 4k limit per cookie, or as a total for all cookies for the domain?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 34

Assisted Solution

by:Paul MacDonald
Paul MacDonald earned 1000 total points
ID: 35483438
4k per cookie, 20 cookies per site.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35483448
0
 

Author Comment

by:nzinsli
ID: 35483462
Thanks.

Is there any real performance concerns in .Net with the code needed to retrieve a cookie value vs parsing the key/value pairs?
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 35483507
Retrieving a cookie requires a round trip to the client.  That's subject to the vagarities of the network.  Parsing key/values will be done as fast as the local machine can make it happen.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35483553
> Retrieving a cookie requires a round trip to the client.  That's subject to the vagarities of the network.  Parsing key/values will be done as fast as the local machine can make it happen.
      

@paulmacd

It does not work that way. The cookies are posted to the server along the request by the client and are parsed on the server.

"When a browser makes a request to the server, it sends the cookies for that server along with the request."


http://msdn.microsoft.com/en-us/library/aa289495%28v=vs.71%29.aspx#vbtchaspnetcookies101anchor8
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 35483565
Hey, I learned something!

In any case, having fewer cookies means less overhead.
0
 

Author Closing Comment

by:nzinsli
ID: 35483591
Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question