<?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>Mike Brittain &#187; cache</title>
	<atom:link href="http://www.mikebrittain.com/blog/tag/cache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikebrittain.com/blog</link>
	<description>Internet, mobile applications, skiing, snowboarding, food... you know, whatever comes to mind.</description>
	<lastBuildDate>Thu, 29 Jul 2010 22:54:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Caching URLs with Query Strings</title>
		<link>http://www.mikebrittain.com/blog/2009/06/11/caching-urls-with-query-strings/</link>
		<comments>http://www.mikebrittain.com/blog/2009/06/11/caching-urls-with-query-strings/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 23:56:44 +0000</pubDate>
		<dc:creator>Mike Brittain</dc:creator>
				<category><![CDATA[WWW]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[cdn]]></category>
		<category><![CDATA[querystring]]></category>
		<category><![CDATA[urls]]></category>

		<guid isPermaLink="false">http://www.mikebrittain.com/blog/?p=347</guid>
		<description><![CDATA[A common method for breaking a cached object, or for specifying a version of an object, is to put a version number into a query string or some other part of the file name.  I&#8217;ve been wary of using query strings in URLs of static assets that I cache, either in browser cache or on [...]]]></description>
			<content:encoded><![CDATA[<p>A common method for breaking a cached object, or for specifying a version of an object, is to put a version number into a query string or some other part of the file name.  I&#8217;ve been wary of using query strings in URLs of static assets that I cache, either in browser cache or on a CDN.  I hadn&#8217;t seen much hard evidence, but generally felt query strings provide another area of uncertainty in a network path that you already have little control over.</p>
<p>Today, I just found Google&#8217;s recommendation for <a href="http://code.google.com/speed/page-speed/docs/caching.html#LeverageProxyCaching">leveraging proxy caches</a>, which states, &#8220;to enable proxy caching for these resources, remove query strings from references to static resources, and instead encode the parameters into the file names themselves.&#8221;</p>
<p>What is a good alternative?  One method I like is to use a version number that is part of the URL path:</p>
<pre>  /12345/css/site.css</pre>
<p>The &#8220;12345&#8243; is prepended in your page templates using a variable.  The value can be taken from anywhere you want&#8230; it could be part of a timestamp, a revision number in your source control, or maybe even manually changed in a constants file anytime your are updating files in your &#8220;css&#8221; directory.  If you&#8217;re using Apache, this portion of the path can be easily stripped off the request using mod_rewrite.</p>
<pre>  RewriteEngine On
  RewriteRule ^/\d{5,}(/.+)$ $1</pre>
<p>With this method, you&#8217;re not literally using directories with version number in them.  Rather, you just use your regular old /htdocs/css directory. The same can be applied to JavaScript, images, or other directories with static assets.</p>
<p>What you gain is the ability to break your cached versions of files when necessary, but to also set long-term cache times on these assets (while they&#8217;re not changing) and expect cache servers between you and your users to properly store these objects.</p>
<h3>More to come&#8230;</h3>
<p>I&#8217;ll be speaking at <a href="http://en.oreilly.com/velocity2009">Velocity</a> in two weeks about how to optimize caching with your CDN.  I have a lot of content that I&#8217;d like to present, but only 20 minutes to do it.  Over the coming weeks I&#8217;ll be writing a number of posts covering topics that don&#8217;t make it into the presentation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikebrittain.com/blog/2009/06/11/caching-urls-with-query-strings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
