Archive for April, 2008

How to use YSlow to get better performance from Rails and Apache 2.2

Saturday, April 19th, 2008


Update: I added the ExpiresByType text/html "access" because our php generated blog content wasn’t refreshing… the text/html content of these sites is pretty light compared to the relatively stable images and css.

I put up a little site some friends and I are playing with. It isn’t much yet and it is far from complete but it is in production… deploy from day one. That’s all automated using the wonderful Capistrano.

Once the site was active I noticed how damn slow it was and decided that I could really do better. Rails was using a fraction of a second per request but the pages were taking seconds to load. Clearly this was a file size issue.

I played around with some stuff in my app layout, specifically:


<%= stylesheet_link_tag :all, :cache => true %>

<%= javascript_include_tag :all, :cache => true %>

The :all will bundle up all the *.js or *.css files up into a single file, cache it (in production) and deliver that as one big bundle cutting down the number of connections that the browser has to make to the server.

Problem remained that the JavaScript was still something like 250kB. Prototype is heavy.

I installed YSlow and took a look at what I could do to improve matters. YSlow is a plugin for Firefox and Firebug that will grade your site A - F on 13 configurations and let you know what to do to make it faster. Pretty neat really.

It seemed like I should be compressing my content using mod_deflate making sure my expires headers were set to the far future so I wouldn’t be re-serving content that hadn’t changed.

Here are the Apache 2.2 configurations that will give some big wins quickly:


ExpiresActive On

ExpiresDefault “access plus 1 year”

ExpiresByType text/html “access”

FileETag none

# Deflate

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/
javascript text/css application/x-javascript

BrowserMatch ^Mozilla/4 gzip-only-text/html

BrowserMatch ^Mozilla/4.0[678] no-gzip

BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

I just slapped those into a file in /etc/apache2/conf.d/yslow-optimizations that is included for all my virtual hosts, automatically giving me fairly decent results for the parts of the site that I can do something about… the blogs, score badly because they pull in content in from all sorts of other web services.

mod_deflate shrinks that massive all.js file from 250kB to about 50kB and the expire settings mean it isn’t served more than once per client. Hot.

So this is the 20% of the effort that I think gets about 80% of the results.

I’d like to understand Etags a bit better, Yahoo reckons that they’re pretty worthless without getting further into how the work specifically and recommend turning them off is usually best.

The other thing I’d like to get a better grip on is minifying my JavaScript files. It would be nice if there was some way to do that on the fly… perhaps with another option to either the Rails tag or have Apache minify them on the fly. Time to start googling for that one. Maybe this?

LOL!!!!1

Sunday, April 13th, 2008

Prompted by a vegetarian co-worker, I took a bite of what looked like a child’s rendering of bacon.

Link

Monica in the Telegraph!

Tuesday, April 8th, 2008

My fantastically talented girlfriend really hit one out of the park here.

Her first article published as a freelance writer is for largest broadsheet in the country, the Daily Telegraph!

Monica-Telegraph-8April08 (1 page).jpg

Link to the article
Link to full size image.