Improving your Rails Application Speed
Your users are happiest when they don't notice how fast your application responds. If your users notice your web application speed it is probably because they notice it is too slow. Most speed improvements happen outside the Rails stack.
Typical page loading time
Here is the output of the Safari Web Inspector - Network report. The page took 3 seconds to load.
Tools of the Trade
The primary tool for analyzing the speed of any web application is Yslow from Yahoo. YSlow grades your application and produces a report:
Safari Develop Menu
Install the Safari Develop Menu with the following command:
$ defaults write com.apple.Safari IncludeDebugMenu 1
The Safari Web Inspector - Network report will produce a report like above showing the amount of time spent loading various components of the page.
Make fewer HTTP requests/Minify JS
$ script/plugin install git://github.com/sbecker/asset_packager.git
Then produce the
$ rake asset:packager:create_yml
You will need to edit the
config/asset_packages.yml file to ensure that the scripts are loaded in the correct order.
application.html.erb layout file place the following:
prototype.js file will be loaded from Google. With any luck the user will already have it cached.
Load files in parallel
Most browsers will make at most two simultaneous requests to each host. Configure your
production.rb to use an assets host:
Of course, you will have to configure
assets.yourhost.com to point to your web server.
Add an expires header/Gzip components
Rails 2.2 supports Etags. Look for another post about Etags in the future.
More reading (update)
For a lot more detailed discussion about improving your sites performance see: Stanford Course CS193H: High Performance Web Sites.