How do I minify CSS in Rails 4?

后端 未结 4 1343
星月不相逢
星月不相逢 2020-12-30 06:18

I tried the following, however I look at the CSS source and it does not minify! I restarted the server several dozen times. I turned off cache in the browser. I also tried t

4条回答
  •  悲哀的现实
    2020-12-30 06:37

    I was having the same problem in my production environment, where I couldn't get the CSS to minify upon deploying to Heroku. After turning on compression with the following:

    production.rb

    config.assets.css_compressor = :sass
    

    Gemfile

    gem 'sass-rails', '~> 4.0.0'    
    

    I managed to get it to minify by updating the assets version:

    production.rb

    config.assets.version = '1.1' # was '1.0'
    

    Doing a few tests afterwards, I found that updating the source CSS/SASS had the same effect. So try updating your stylesheets (as opposed to only the config), which should "kickstart" the minification process when Heroku precompiles your assets after you push, without needing to update the assets version.

提交回复
热议问题