<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Made of Everything You&#039;re Not &#187; cookies</title>
	<atom:link href="http://blog.ericlamb.net/tag/cookies/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ericlamb.net</link>
	<description>Thoughts on programming, people and life</description>
	<lastBuildDate>Thu, 29 Jul 2010 07:00:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Sometimes, Poor Design Works</title>
		<link>http://blog.ericlamb.net/2009/06/sometimes-poor-design-works/</link>
		<comments>http://blog.ericlamb.net/2009/06/sometimes-poor-design-works/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 13:00:17 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Brain Dump]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[program design]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=1814</guid>
		<description><![CDATA[As programmers, we can get obsessed with the small things. I personally have no problem spending hours trying to optimize a section of code, not for performance or to improve user experience or anything like that, but because there&#8217;s just something funny about the algorithm. The professional in us tries, sometimes futily, to keep this behavior [...]]]></description>
			<content:encoded><![CDATA[<p>As programmers, we can get obsessed with the small things. I personally have no problem spending <em>hours</em> trying to optimize a section of code, not for performance or to improve user experience or anything like that, but because there&#8217;s just something <em>funny</em> about the algorithm.</p>
<div id="attachment_1827" class="wp-caption aligncenter" style="width: 235px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/06/cookie.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F06%2Fcookie.png','HTTP+Cookie')"><img class="size-full wp-image-1827" title="HTTP Cookie" src="http://blog.ericlamb.net/wp-content/uploads/2009/06/cookie.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F06%2Fcookie.png','HTTP+Cookie')" alt="HTTP Cookie" width="225" height="157" /></a><p class="wp-caption-text">HTTP Cookie</p></div>
<p>The professional in us tries, sometimes futily, to keep this behavior in check. Sometimes though you just have to do &#8221;just&#8221; one more thing to really make it perfect.  This, more often than not, balloons up into a weeklong chore to, in the end, dig yourself out of the hole you made with zero progress on the initial problem.</p>
<p>This is the way of the code monkey.</p>
<p>Which is why it&#8217;s a little surprising to see how <a title="HTTP Cookies" href="http://en.wikipedia.org/wiki/Cookie_(browser)" onclick="return TrackClick('http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FCookie_%28browser%29','HTTP+Cookies')" target="_blank">HTTP cookies</a> are implemented. According to the official RFC (<a title="HTTP State Management Mechanism" href="http://tools.ietf.org/html/rfc2109" onclick="return TrackClick('http%3A%2F%2Ftools.ietf.org%2Fhtml%2Frfc2109','HTTP+State+Management+Mechanism')" target="_blank">HTTP State Management Mechanism</a>):</p>
<blockquote><p>The user agent makes a series of requests on the origin server, after each of which it receives a new cookie. All the cookies have the same Path attribute and (default) domain. Because the request URLs all have /acme as a prefix, and that matches the Path attribute, each request contains all the cookies received so far.</p></blockquote>
<p>Think about that for a second. On every request the cookies are sent to the server. ON EVERY REQUEST.</p>
<p>Try this; install a FireFox plugin called <a title="Live HTTP Headers" href="http://livehttpheaders.mozdev.org/" onclick="return TrackClick('http%3A%2F%2Flivehttpheaders.mozdev.org%2F','Live+HTTP+Headers')" target="_blank">Live HTTP Headers</a> (if you don&#8217;t already have it installed). Start the plugin and refresh this page.</p>
<div id="attachment_1834" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/06/live_http_headers.gif" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F06%2Flive_http_headers.gif','Live+HTTP+Headers')"><img class="size-medium wp-image-1834" title="Live HTTP Headers" src="http://blog.ericlamb.net/wp-content/uploads/2009/06/live_http_headers-300x200.gif" alt="Live HTTP Headers" width="300" height="200" /></a><p class="wp-caption-text">Live HTTP Headers</p></div>
<p>You should notice that every request for ANYTHING (images, js, css) sends the cookies up to the server.</p>
<p>I don&#8217;t know about you, but I only have one or <em>maybe</em> two, points in an application that can evaluate cookies so to send on every request is a little&#8230; wasteful.</p>
<p>I don&#8217;t know for sure if there&#8217;s more work on the server side to deal with the cookies (though I would imagine the HTTP server has to do <em>something </em>to make the cookies available to a scripting language) but what I focus on is the bandwidth.</p>
<p>Now, I know it&#8217;s the 21st century and bandwidth is now fast and cheap. Yay us.</p>
<p>But consider the state of the Internet and bandwidth in 1997 when the specification was first drafted. Most people were using 28.8 and 33.6 baud modems to browse the Internet and <a title="56k Modem History" href="http://en.wikipedia.org/wiki/56k_modem" onclick="return TrackClick('http%3A%2F%2Fen.wikipedia.org%2Fwiki%2F56k_modem','56k+Modem+History')" target="_blank">56k was still a year away</a>.</p>
<p>According to the spec:</p>
<blockquote><p>Practical user agent implementations have limits on the number and size of cookies that they can store.  In general, user agents&#8217; cookie support should have no fixed limits. They should strive to store as many frequently-used cookies as possible.  Furthermore, general-use user agents should provide each of the following minimum capabilities individually, although not necessarily simultaneously:</p>
<p>* at least 300 cookies</p>
<p>* at least 4096 bytes per cookie (as measured by the size of the characters that comprise the cookie non-terminal in the syntax description of the Set-Cookie header)</p>
<p>* at least 20 cookies per unique host or domain name</p>
<p>User agents created for specific purposes or for limited-capacity<br />
devices should provide at least 20 cookies of 4096 bytes, to ensure<br />
that the user can interact with a session-based origin server.</p></blockquote>
<p>So, unless I&#8217;m crazy, the above makes it acceptable for a site to use 20 cookies, each with a maximum size of 4096 bytes (4Kb). This equals out to a possible 81920 (82Kb) bytes of cookie data being sent on EVERY REQUEST.</p>
<p>This basically means that an image that weighed in at a cool 2Kb comes out to need 82Kb of bandwidth to transfer. Doing the math on a full site with say 20 images, 1 HTML file, 1 CSS file and 3 JS files and it really starts to add up. So at a time when bandwidth was scarce cookie usage was a good way to screw up the user experience if you didn&#8217;t pay attention.</p>
<p>Granted, you&#8217;d have to be an <em>idiot</em> to write a program that used 20 cookies with each containing 4kb of data, but we&#8217;re programmers. Most of us are stupid; some are really stupid.</p>
<p>It&#8217;s easy to point at cookies and laugh.</p>
<p>The thing we need to keep in mind, though, is that this isn&#8217;t <del datetime="2009-06-05T23:05:46+00:00">a</del> that big a problem anymore. Sure, once, it may have been an <del datetime="2009-06-05T23:05:46+00:00">possible</del> issue. Technology <ins datetime="2009-06-05T23:05:46+00:00">almost</ins> solved it though. Faster bandwidth, with faster computers <del datetime="2009-06-05T23:05:46+00:00">made</del> <ins datetime="2009-06-05T23:05:46+00:00">will eventually make</ins> any issue just disappear.</p>
<p>Which is kind of the point; something I try to keep in mind.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/06/sometimes-poor-design-works/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
