Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to combine and minify JS / CSS on Heroku

First of all, according to this answer, the :cache => true option on stylesheet_link_tag and javascript_include_tag doesn't work on Heroku. Is this true? I've found :cache => true to work occasionally, but not always (weird!)

Also, what's the best solution here? Ideally it would seamlessly combine and minify all CSS / JS. Heroku Asset Packager claims to do this -- are there better options?

like image 475
Tom Lehman Avatar asked Dec 11 '09 18:12

Tom Lehman


People also ask

How do you minify CSS and JS files?

To minify CSS, try CSSNano and csso. To minify JavaScript, try UglifyJS. The Closure Compiler is also very effective. You can create a build process that uses these tools to minify and rename the development files and save them to a production directory.

How do you minify Javascript and HTML?

Go to minifycode.com and click the CSS minifier tab. Then paste the CSS code into the input box and click the Minify CSS button. After the new minified code is generated, copy the code. Then go back to the css file of your website and replace the code with the new minified version.


1 Answers

I'm using Jammit on Heroku. Works Great. You can locally build your assets and check in to heroku. use

jammit --force 

the current version 0.5.1 has issues working on heroku but you can install the fixed version from git://github.com/documentcloud/jammit.git

If you are using Rails 3, specify the below in your bundler Gemfile:

gem "jammit", :git => "git://github.com/documentcloud/jammit.git" 

For Rails 2.*

config.gem "jammit", :source => "git://github.com/documentcloud/jammit.git" 

Good Luck.

like image 99
Greg Avatar answered Sep 24 '22 03:09

Greg