Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails not minifying

I'm working on a project that does not minify CSS or JS in production.

Unfortunately I've never had this problem, and I'm just not very familiar with how the asset pipeline works in detail to debug the issue.

My question is, what are the main points/settings that I need to check to make sure that is enabled?

It is properly combining the different files into a single JS and CSS file... it's just not minifying.

So far I've added config.assets.js_compressor = :uglifier to production.rb, and uglifier to the Gemfile, but still no dice.

I'm using a Rails 3.2.12 upgraded from Rails 2

like image 349
Tallboy Avatar asked Oct 07 '13 21:10

Tallboy


1 Answers

This answer applies for rails 4

One of the reasons when rails-4 won't minify assets is when the RAILS_ENV is not set to production.

This usually happens when you pre-compile assets and run webrick in prod mode using:
rails s -e 'production'
but still the resulting application.css and application.js are concatenated but not minified.

To solve this, use the following to specify the env while precompiling assets:

$ RAILS_ENV=production bundle exec rake assets:precompile

Also if you are upgrading from rails 3 to rails 4, please note that config.assets.compress = true directive in production.rb is not longer effective for rails 4. You'll need to add the following directives in your config/environments/production.rb file for it to minify js and css files:

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier # make sure the 'uglifier' gem is included before adding this line
  config.assets.css_compressor = :sass # if you are using the sass-rails gem, this line is unnecessary
like image 103
CodeExpress Avatar answered Sep 28 '22 07:09

CodeExpress