Disable Asset Minification in Rails Production

In order to debug javascript in my heroku production environment, I need to disable asset compression (or at least compression of javascript). I tried config.assets.compress = false along with config.assets.debug = true , and the compressed assets were still used. I then deleted the compressed assets, at which point no assets were rendered at all. I added config.assets.enabled = false , which did not help. I tried copying the uncompressed assets into various directories, including the application root, public, and public/assets (the latter two using both the folders "images, "javascripts", and "stylesheets", and putting the assets directly into the folders without the three subfolders). I was eventually able to get the javascripts to work by changing the html to directly reference all of the javascript files. But the CSS and images still are not working.

I would have thought that my original config.assets.compress = false should have worked. Any ideas what I did wrong?


I came up with this workaround after reading the docs:

create a module that does nothing to compress js / css here: lib/modules/no_compression.rb

class NoCompression
  def compress(string)
    # do nothing
    string
  end
end

configure your assets to (not) be compressed with your do-nothing compressor

config.assets.compress = true
config.assets.js_compressor = NoCompression.new
config.assets.css_compressor = NoCompression.new

Under Rails 4 just commenting out the line

# config.assets.js_compressor = :uglifier

in config/environments/production.rb worked for me. Looks like default is no compresson.


I also need to debug my js so I tried ncherro's solution. The problem was that it would still throw

rake aborted! uninitialized constant NoCompression

So I just put the NoCompression class in the production.rb file

    # Compress JavaScripts and CSS
    class NoCompression
         def compress(string)
             # do nothing
             string
         end
     end

     config.assets.compress = true
     config.assets.js_compressor = NoCompression.new
     config.assets.css_compressor = NoCompression.new
链接地址: http://www.djcxy.com/p/79010.html

上一篇: 在Rails资产管道中使用字体

下一篇: 在Rails生产中禁用资产缩减