Orion_Blue
Orion_Blue

Reputation: 15

iIs there a benefit to using to the asset pipeline in rails for your javascript files and stylesheets?

I was just wondering what are the benefits of using the asset pipeline in Rails for JavaScript and stylesheets?

I just started to work on an older Rails application which we are trying to convert to Rails 4, that doesn't use the asset pipeline as a core feature.

I am hoping to give some good reason why we should start using the asset pipeline. I know we could start using CoffeeScript and Sass.

I was wondering what are the other benefits to it?

Upvotes: 0

Views: 149

Answers (1)

sadaf2605
sadaf2605

Reputation: 7540

Few of the key benefits are:

  • It reduces bandwidth. Raw Javascript and CSS files wastes a lot of bandwidth with comments, extra white space, and long variable names. So rails asset pipeline compress these files and reduces bandwidth.

  • It handles asset chaching. Another issue that comes up is caching. When you serve up a Javascript file from your server, for example, the browser will automatically cache that file for a period of time. That improves page load time, but what if that asset changes at a later point in time? The browser won’t know about it, so it will continue to use the cached asset until its cache life has expired. Rails asset pipeline solves this problem with fingerprint.

  • It pre-process more organizable scripts for browswer. Languages such as Coffeescript, Sass, Less, and Erb have made it easier to organize and write Javascript and CSS, but the browser can’t interpret them directly, so a pre-processor is needed to convert those files into their appropriate counterparts before they are sent off to the browser.

Upvotes: 3

Related Questions