Trick to improve performance in rails, less requests with static resources

Posted by Pablo Ifran on April 08, 2009

Reducing the number of request made to the server improves the performance of a web application in about 80%.

There are many techniques that allow us to reduce the amount of requests that are made on a page, among them are: the sprites, put the stylesheets on top of the page, javascripts compress, among others.

But what’s offered by Rails to improve the performance of our web application?

It offers a great plugin called bundle_fu (http://code.google.com/p/bundle-fu/)
It allows us with a single request obtain all the javascripts and with another request all the stylesheets  (it also offers the possibility of compress javascripts).
Using this plugin is really easy but it’s very powerfull

<% bundle do -%>
  <%= javascript_include_tag :default -%>
  <%= javascript_include_tag "javascript1" -%>
  <%= javascript_include_tag "javascript2" -%>
  <%= javascript_include_tag "javascript3" -%>
  <%= stylesheet_link_tag "style1" -%>
  <%= stylesheet_link_tag "style2" -%>
  <%= stylesheet_link_tag "style3" -%>
  ...
<% end %>

All these javascripts and stylesheets are converted in only two files when the request is processed.

[Post to Twitter] Tweet This Post 


Tweet This Post links powered by Tweet This v1.3.9, a WordPress plugin for Twitter.