gak
gak

Reputation: 32763

Different JS files using Rails asset pipeline in development mode?

I would like to have the non-minified version of JavaScript libraries being used in development, and the minified versions used elsewhere.

How would I go about doing this if I'm using Rails assets?

I'm including like this:

application.haml

= javascript_include_tag :application

application.js

//= require jquery/jquery-1.7.2.min.js
//= require jquery/jquery-ui-1.8.20.custom.min.js
... and many more

Upvotes: 1

Views: 354

Answers (1)

deefour
deefour

Reputation: 35360

The better thing to do is use the :debug option

= javascript_include_tag "application", debug: Rails.env.development?

In debug mode, assets are not minified.

If you're actually maintaining 2 versions of each library (for example, a minified and raw version of jQuery), this is unnecessary. If you want to see the raw jQuery source in your browser's console, you should always use the unminified version of the library in combination with the :debug option above.

  • In development an unminified version of jQuery will be included in it's own <script> tag
  • in production jQuery will be minified and concatenated with all other assets in application.js in a single <script> tag.

Upvotes: 2

Related Questions