AnApprentice
AnApprentice

Reputation: 111090

How to minify JavaScript & CSS using Rails 4?

I'm currently using Rails 4. My settings:

production.rb

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

My understanding is Rails 4 is supposed to minify JS and CSS however when I run Page Speed Insights, I'm being told I need to minify my JS & CSS.

What am I doing wrong? How do I get my Rails 4 app to minify JS and CSS and make Google PageSpeed happy?

Upvotes: 2

Views: 4402

Answers (1)

vanboom
vanboom

Reputation: 1332

http://guides.rubyonrails.org/asset_pipeline.html#css-compression

If your Gemfile includes sass-rails, CSS will be minified by default as long as config.assets.compress = true in your production.rb

To compress JS, you can use config.assets.js_compressor = :uglifier

Make sure uglifier is in your Gemfile.

Upvotes: 2

Related Questions