Enable Asset Compression After Upgrading to Rails 4

28 Nov 2014

Recently, I upgraded an app from Rails 3.2 to 4.0. Things went smoothly, but I recently noticed that the JavaScript response was twice the size I expected it to be. Taking a closer look showed that Rails was no longer minifying the JS assets.

It turns out that the config.assets.compress = true directive no longer works in Rails 4. Instead, you need to specify the compressor in config/environment/production.rb like this:

MyApp::Applicationdoconfig.assets.js_compressor=:uglifierend

It is strange that this was changed without any deprecation messages, but luckily it didn’t cause much damage.

Hi, I’m Nithin Bekal.
I work at Shopify in Ottawa, Canada.
Previously, co-founder of
CrowdStudio.in and
WowMakers.
Ruby is my preferred programming language,
and the topic of most of my articles here,
but I'm also a big fan of Elixir.
Tweet to me at @nithinbekal.