<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Caching and MIME Types in Rails</title>
	<atom:link href="http://www.igvita.com/2007/06/13/caching-and-mime-types-in-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.igvita.com/2007/06/13/caching-and-mime-types-in-rails/</link>
	<description>A goal is a dream with a deadline.</description>
	<pubDate>Fri, 29 Aug 2008 04:17:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2007/06/13/caching-and-mime-types-in-rails/#comment-104547</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Tue, 01 Jul 2008 00:36:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/06/13/caching-and-mime-types-in-rails/#comment-104547</guid>
		<description>Cedric, awesome, thank you for sharing the Apache config! It looks like we came up with the same solution, albeit for Nginx at AideRSS: &lt;a href="http://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/" rel="nofollow"&gt;Nginx and Memcached&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>Cedric, awesome, thank you for sharing the Apache config! It looks like we came up with the same solution, albeit for Nginx at AideRSS: <a href="http://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/" rel="nofollow">Nginx and Memcached</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cédric DELTHEIL</title>
		<link>http://www.igvita.com/2007/06/13/caching-and-mime-types-in-rails/#comment-104221</link>
		<dc:creator>Cédric DELTHEIL</dc:creator>
		<pubDate>Wed, 25 Jun 2008 07:22:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/06/13/caching-and-mime-types-in-rails/#comment-104221</guid>
		<description>Ilya,

Forcing type is a nice trick!

On my own, I experienced some other problems with the combination of page caching and REST style architecture while using different formats (ie. Rails respond_to).
In other words, I noticed that your rewriting rules should be robust enough to handle the use or not of format as query string:

&lt;code&gt;
GET /foo/1?format=json
GET /foo/1.json
&lt;/code&gt;

So how can we handle MIME type and various format together? I suggest the following Apache configuration that does the trick:

&lt;code&gt;
# 1. Rewrite when the format is specified as a query string
# eg. /foo/1?format=json =&#62; /foo/1.json
RewriteCond %{QUERY_STRING} format=(html&#124;xml&#124;json)
RewriteRule ^(.*)$ $1.%1 

# 2. Rewrite to check for static
# eg. /foo/1.json =&#62; /cache/foo/1.json
RewriteRule ^(.+\.(html&#124;xml&#124;json))$ /cache$1

# 3. Force the MIME type with 'type' special flag
# eg. remember /cache/foo/1.json to have MIME-type 'application/json'
RewriteCond $1 ^.+\.json$
RewriteRule ^(.*)$ $1 [T=application/json]

# etc such forcing other types or redirecting non-statics requests
&lt;/code&gt;

Hope it'll be useful to someone else!</description>
		<content:encoded><![CDATA[<p>Ilya,</p>
<p>Forcing type is a nice trick!</p>
<p>On my own, I experienced some other problems with the combination of page caching and REST style architecture while using different formats (ie. Rails respond_to).<br />
In other words, I noticed that your rewriting rules should be robust enough to handle the use or not of format as query string:</p>
<p><code><br />
GET /foo/1?format=json<br />
GET /foo/1.json<br />
</code></p>
<p>So how can we handle MIME type and various format together? I suggest the following Apache configuration that does the trick:</p>
<p><code><br />
# 1. Rewrite when the format is specified as a query string<br />
# eg. /foo/1?format=json =&gt; /foo/1.json<br />
RewriteCond %{QUERY_STRING} format=(html|xml|json)<br />
RewriteRule ^(.*)$ $1.%1 </p>
<p># 2. Rewrite to check for static<br />
# eg. /foo/1.json =&gt; /cache/foo/1.json<br />
RewriteRule ^(.+\.(html|xml|json))$ /cache$1</p>
<p># 3. Force the MIME type with 'type' special flag<br />
# eg. remember /cache/foo/1.json to have MIME-type 'application/json'<br />
RewriteCond $1 ^.+\.json$<br />
RewriteRule ^(.*)$ $1 [T=application/json]</p>
<p># etc such forcing other types or redirecting non-statics requests<br />
</code></p>
<p>Hope it&#8217;ll be useful to someone else!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2007/06/13/caching-and-mime-types-in-rails/#comment-102113</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Tue, 18 Mar 2008 12:36:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/06/13/caching-and-mime-types-in-rails/#comment-102113</guid>
		<description>Nick, I submitted the patch to Chris before, but it never made it in. And you're right, I also had to modify the code when porting to Rails 2.x - unfortunately I wasn't smart enough to make a diff at the time! Any chance you can submit your changes? 

With luck it'll get integrated this time.</description>
		<content:encoded><![CDATA[<p>Nick, I submitted the patch to Chris before, but it never made it in. And you&#8217;re right, I also had to modify the code when porting to Rails 2.x - unfortunately I wasn&#8217;t smart enough to make a diff at the time! Any chance you can submit your changes? </p>
<p>With luck it&#8217;ll get integrated this time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Grandy</title>
		<link>http://www.igvita.com/2007/06/13/caching-and-mime-types-in-rails/#comment-101919</link>
		<dc:creator>Nick Grandy</dc:creator>
		<pubDate>Tue, 11 Mar 2008 03:40:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/06/13/caching-and-mime-types-in-rails/#comment-101919</guid>
		<description>Ilya,
Great patch, thanks a ton.  I was having trouble caching RJS actions in Rails - that is, actions that product javascript.  I'd think this is a pretty critical workaround for anyone trying to do the same.  FYI, The patch no longer seems entirely compatible with cache fu. I had to get in there and apply part of the patch manually.  But all the better - now I actually see what's going on.  Would be great if this gets incorporated into cache fu.  Chris just opened up a new git repository to help accomodate changes.</description>
		<content:encoded><![CDATA[<p>Ilya,<br />
Great patch, thanks a ton.  I was having trouble caching RJS actions in Rails - that is, actions that product javascript.  I&#8217;d think this is a pretty critical workaround for anyone trying to do the same.  FYI, The patch no longer seems entirely compatible with cache fu. I had to get in there and apply part of the patch manually.  But all the better - now I actually see what&#8217;s going on.  Would be great if this gets incorporated into cache fu.  Chris just opened up a new git repository to help accomodate changes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2007/06/13/caching-and-mime-types-in-rails/#comment-101255</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Thu, 31 Jan 2008 06:28:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/06/13/caching-and-mime-types-in-rails/#comment-101255</guid>
		<description>Andrew, I don't think the patch made it into the trunk. Having said that, I'm aware of at least several sites that are using it now!

As for page caching, yes that would be ideal. However, in a lot of cases you simply can't rely on file extensions due to URI structure, and hence all MIME magic tends to break down.</description>
		<content:encoded><![CDATA[<p>Andrew, I don&#8217;t think the patch made it into the trunk. Having said that, I&#8217;m aware of at least several sites that are using it now!</p>
<p>As for page caching, yes that would be ideal. However, in a lot of cases you simply can&#8217;t rely on file extensions due to URI structure, and hence all MIME magic tends to break down.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Turner</title>
		<link>http://www.igvita.com/2007/06/13/caching-and-mime-types-in-rails/#comment-101231</link>
		<dc:creator>Andrew Turner</dc:creator>
		<pubDate>Tue, 29 Jan 2008 18:33:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/06/13/caching-and-mime-types-in-rails/#comment-101231</guid>
		<description>Was this ever acccepted into cache_fu proper? 

Also, it seems awkward to require a different action to handle just RSS. This is the purpose of the respond_to block for single action logic, different methods of rendering.

What would be the best would be if the page caching stored the static page with the appropriate extension and MIME-Type.</description>
		<content:encoded><![CDATA[<p>Was this ever acccepted into cache_fu proper? </p>
<p>Also, it seems awkward to require a different action to handle just RSS. This is the purpose of the respond_to block for single action logic, different methods of rendering.</p>
<p>What would be the best would be if the page caching stored the static page with the appropriate extension and MIME-Type.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
