Making YSlow Happy With Rails, Apache, Passenger

Over the past month I’ve been obsessed with speeding up a Rails app that I perceived to be slow ( Requests would take half a second minimum and only 50 db queries if lucky. One I saw one at 183, I went on a mission.

Most of the work was implementing fragment caching and chasing down n+1 queries. This cut the average Rails response time by 75%. It would be worth another blog post. Since it’s still not where I’d like it to be, that post will have to wait.

Meanwhile, these two things had the most impact on increasing my perception of speed (and increasing the YSlow grade from C to B). They were not in the application but in the vhosts config on Apache.

1. Set an Expires header that plays ball with Rails asset tags. I looked at several pages before I found this discussion of how to implement far future expires headers that don’t invalidate Rails asset tags.

YSlow’s Expires header component went from F to A.

Read the article, use the last code block.

2. I followed this advice and turned off ETags until I have a fine-grained reason to use them.

YSlow’s Configure ETags component went from F to A. Apparently “configure” is another word for “remove” when it comes to YSlow and ETags.

Now the site feels pretty snappy, especially if you turn off Firebug, which got really slow after I installed FireQuery.

November 15, 2009 in Ruby on Rails