Promine

Nossas idéias para você…

asset_packager tips rodrigofelix

July 5, 2010 Development

Before publishing your Rails application, it is very important to care about performance. When we think about performance some issues like caching and compression come up to our minds. A great Firefox plugin to analyze and improve your web app perfomance is the YSlow one integrated with the Firebug. With YSlow you can see which are your web site bottlenecks. A very common and useful action you can take is reducing the number of HTTP requests and minifying javascript and stylesheet files.

According to the HTTP rules, each web site file (like images, javascript, …) is sent to the browser on a different response message. So, it’s quite straightforward to think about putting somehow many files together to reduce the number of responses. Using the asset_packager plugin, you can run a rake task to aggregate and minify stylesheets and javascripts. I do advise you to use this plugin, but take a look at the following tips in order to save some time and avoid issues when publishing your web site.

  1. Remove @charset at-rule: Some IDEs automatically add a @charset “iso-8859-1″ line, for example, at the top of stylesheet files. When you run rake asset:packager:build_all that line may broke the generated packaged file.
  2. Avoid/Remove @import at-rule: The @import CSS rule allows you to include external stylesheets in your document. However, you can mess your site layout up if you use it, since it doesn’t follow the loading order you defined on the config/asset_packages.yml. If you want to reuse files, split your files as you prefer and group them on the asset_packages.yml.
  3. Avoid compressed javascripts: The most common js libraries has a minified version. As asset_packager compresses js files, avoid re-compressing those files. If you prefer minified files, you shouldn’t include them into the asset_packages.yml.
  4. Test your app on the production environment: Before publishing your app, test it on the production environment (script/server -u RAILS_ENV=production). You can find some layout bugs.

That’s it. If you have any further tip, please, let me know, leave a comment.

Popularity: 4% [?]

Write a Comment