Archive

Archive for April, 2009

:cache => true

April 27th, 2009 mahesh No comments

That is all it took to take my site from F grade to B and make my site faster by 1 second almost! So, if you have a rails app, go ahead and add :cache => true to your stylesheet_link_tag and javascript_include_tag in your view files. This is all I added into my application.html.erb

<%= stylesheet_link_tag "home", :media => "all", :cache => true %>
<%= javascript_include_tag :all, :cache => true %>

All rails does is collapses all your javascript (and stylesheet) files into single file. I have 11 javascript files and 3 css files. With this, I reduced the number of calls by 12 and that gave a good one second improvement! Not bad ha? Also, that one second was pretty consistent with/without firefox caching.

After this, I tried using asset_packager plugin to see if I get any more improvement. But, I didn’t really see any. Basically, that minifies your files by combining everything into one file and removing new line character and stuff.

The video tutorial had a few more suggestions like using CDN which clearly is not something I would like to explore at this point because it costs money.

That’s all for now. Stay tuned for more improvements as I go through next tutorials.

Cheers,
Mahesh Murthy

Categories: Uncategorized Tags:

How fast is your website?

April 15th, 2009 mahesh No comments

I was searching for rails caching tutorials and ran into this really nice set of video tutorials about scaling rails applications on newrelic. I just watched the first video which has some neat tricks on how to improve the page load time. I ran some tests on thecollegestuff.com and here are the stats.

1. According to firebug, the site load time is 3.5 seconds and the breakdown is as follows

firebug

2. Then the tutorial mentioned about yslow and how to use it to collect some stats. Here is the output from yslow.

yslow

Ugh .. my site has a rating F!

Over the next few days, I will try to implement all the things suggested in the tutorials. Let’s see how much improvement I will get out of it.

Have a nice day!
Mahesh Murthy

Categories: Uncategorized Tags:

Note on page caching

April 12th, 2009 mahesh No comments

It turns out I can’t use page caching like the way I did in the previous post. The way page caching works is that rails just saves the rendered html in the public directory and next time when the request comes in, if the page exists, it just fetches it. The problem is, if a user is logged in, his name shows up on the top right corner of the page. Now let’s say on the first hit for user foo, rails caches the page. When someone else accesses the same url, rails happily fetches the cached page (with user name foo) to user bar. yikes! User bar is all confused now. Not good.

Moral of the story: Page caching should be used for pages which don’t have any customized information.

What I really need is action caching. Back to the drawing board! I will blog about it when I am done.

See you later,
Mahesh Murthy

Categories: Uncategorized Tags: