Last Updated: February 25, 2016
·
843
· jaketollette

Heroku assets not minified?

I finished my brand new portfolio website the other day and after setting up caching, compression, and installing necessary gem for compression on Heroku, heroku-deflater, I thought I'd check with PageSpeed Insights and see just how blazing fast my new application was. And then it hit me with a bunch of... suggestions. A couple surprised me. It said I should minify my JS and CSS.

I checked config/environments/production.rb and made certain that the applicable compressors were set as so:

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

I hit the normal places and quickly found an answer at StackOverflow that was only relevant due to a comment on the answer. I had been precompiling as I should, but I didn't clear everything and somehow that was causing a problem, so here was my solution:

rake assets:clobber 
rake RAILS_ENV=production assets:precompile

The first command, rake assets:clobber, completely wipes your assets. To quote the documentation it "nukes public/assets".

rake assets:clean is what I had been using, but that only removes old assets and keeps the 3 most recent copies. Not what I needed.

After running the appropriate commands, my assets were properly compressed and minified. Hopefully, you can learn from my mistake.


Reference

Sprocket-Rails Documentation