Best way to combine and minify JS / CSS on Heroku

后端 未结 8 1277
梦谈多话
梦谈多话 2020-12-24 06:39

First of all, according to this answer, the :cache => true option on stylesheet_link_tag and javascript_include_tag doesn\'t work o

相关标签:
8条回答
  • 2020-12-24 07:11

    Here are the config options to compress your assets.

    http://guides.rubyonrails.org/asset_pipeline.html#customizing-the-pipeline

    config.assets.css_compressor = :yui
    config.assets.js_compressor = :uglifier
    config.assets.compress = true
    
    
    gem 'uglifier'
    gem 'yui-compressor'
    
    0 讨论(0)
  • 2020-12-24 07:19

    There are probably various ways to do this, but what works for me is to minify before pushing. Then I use a subtree to keep my build files separate from the "source" files. So, for example, if you build to a folder called "dist", you can push to a subtree called heroku/master like this:

    git subtree push --prefix dist heroku master
    

    Just don't forget to ensure that the dist folder is not ignored (it often is, by default) - so edit your .gitignore file accordingly.

    The --prefix command ensures that the dist folder effectively becomes the "root" folder from the point of view of that branch.

    0 讨论(0)
提交回复
热议问题