Please welcome a new thingie I just released – yui_compressor_fu.
Point
yui_compressor_fu delicately minifies all your assets (linked with javascript_include_tag, stylesheet_link_tag helpers) with YUI Compressor. It abides Rails caching rules. All you have to do is install the plugin, and minifying will automatically kick-in when rails performs its normal caching routines.
Tale
Today I was having my usual cup of Earl Grey with lemon while trying to find some JS/CSS minifying solution. Nowadays Rails provides built-in concatenation and caching, but not compression. I wanted to find something that transparently adds some minifying to the mix. Well, not so fast.
After flipping through quite a few choices, I wasn’t impressed at all. Available plugins either require too much configuration (why do I have to list all my assets again, asset_packager?) or they use inferior compression algorithms (Packer/MinJS). According to my research (don’t quote me) – YUI Compressor kicks some major ass. A few minutes of fruitless digging later I decided to make this plugin instead.
Feel free to try it out and let me know of any issues you encounter.
[...] yui_compressor_fu – Automatic minimization of CSS/JavaScript for Rails applications. [...]
This is excellent. I don’t like that existing solutions like asset packager force you to keep a separate list of your JavaScript and CSS files outside of your code.
Thanks for the feedback. : )
I wrote this exact same plugin a few months ago: http://github.com/joevandyk/fixie_shrinker/tree/master
Except that my plugin compresses the CSS and JS whenever those files change in development mode, so you’re ensured that your JS and CSS will compress correctly.
Looks good. My goal was to simply add one more step to rails already-existing concat/caching. Rails is smart enough to track asset changes and rewrite files when necessary. I’m just piggybacking on that mechanism. To test minifying in development mode all you have to do is enable caching in dev – just like when you want to see concatenation in dev mode.
Hi, I’ve spent time today looking into this whole YUICompressor vs other approaches. Glad to find your link before I start doing my own customized Capistrano tasks to help integrating YUICompressor with my deployed Rails app.
Two thoughts: 1. Glad to see that you include the latest YUICompressor jar in the plugin! Now… if only this plugin can help install Java on the deployment machine. xD It’s such a pain to install Java on Linux. (I know this is a wishful thinking. :)
Thanks for sharing this neat, little plugin! If only YUICompressor has a Ruby version, I am sure this would become a very popular integration choice and plugin.
Thanks for suggestions.
I spent a bit of time just now looking up some solutions. Looks like it’s not that bad to integrate Java and Ruby (e.g. JRuby or gcj + swig) so perhaps there is a worry-free way to call yuicompressor directly without installing java. When I get more time, I will look into that and see how far I can go :) But yeah, even though on Centos it doesn’t look as easy as on Ubuntu, it’s something one has to deal with to get up and running.