rails/rails — Issue #5145: Asset Pipeline ignores assets.compress config option
Author: fullbridge-batkins
Created: 2012-02-23 20:34:32+00:00
State: open

When you create a brand new application using `rails 3.2.x`, the default configuration for the asset pipeline in the `development` environment, as set in `config/environments/development.rb` is as follows:

# Do not compress assets
config.assets.compress = false

# Expands the lines which load the assets
config.assets.debug = true

This is described in the Asset Pipeline documentation [as shown here](http://guides.rubyonrails.org/asset_pipeline.html#upgrading-from-old-versions-of-rails). Unfortunately, this setup doesn't actually work out of the box. If you generate a brand new application with a basic controller serving up a page with plain text, and then inspect the code, you'll notice that it does indeed acknowledge the `config.assets.debug = true` option, as multiple javascript files will be included (`jquery.js` and `jquery_ujs.js` are provided by default).

However, if you inspect what's inside of the `application.js` file that is being served up, you will notice that it is actually a compressed combination of all the others. This must mean that `config.assets.compress = false` is being ignored and treated as `true` no matter what.

You'll also notice that if you inspect the javascript console in a browser like chrome, it causes a javascript error to be thrown with this message: `Uncaught TypeError: undefined is not a function (application.js:32)`. Worse yet, all jquery scripts cease to function properly if you try to run with it like this. I believe the error is thrown as a result of jQuery being included twice, but it's difficult to tell for certain since the `application.js` file is compressed.

Note that the application will still function fine in `production` mode, but it doesn't work properly in `development` mode. Now there are two possible workarounds; the first is to set `config.assets.debug = false`, which will prevent the individual javascript files from being served up. This defeats the purpose of the development mode configuration, as the application will essentially work as though it's being run in production mode (with just one giant compressed `application.js` file). The second, more functional workaround, [as found here](http://stackoverflow.com/questions/8356251/rails-3-1-assets-strange-serving-in-development) is to add `config.serve_static_assets = false` to your `config/environments/development.rb` file. This will only work if you run `rake assets:precompile` at least once.

The fact remains that this is a bug, and that unless this is addressed, the `assets.compress` option is essentially useless without a hack workaround.

I am not the first to acknowledge this. It has been mentioned in [this issue report](https://github.com/rails/rails/issues/5095), as well as [this post on StackOverflow](http://stackoverflow.com/questions/8356251/rails-3-1-assets-strange-serving-in-development). Pardon me for re-posting this but I feel the other issue is mislabeled.