Thursday, October 18th, 2007
PackR: Rails Packing
<>p>James Coglan has produced a Rails plugin to handle Dean Edwards Packer.PackR allows you to programatically compress:
-
# Create a new instance of Packr first
packr = Packr.new
compressed = packr.pack(script)
# Pass options to control the type of compression
compressed = packr.pack(script, :shrink_vars => true)
compressed = packr.pack(script, :base62 => true)
compressed = packr.pack(script, :shrink_vars => true, :base62 => true)
or you can use the rake task:
rake packr:pack_libs
Related Content:











Doesn’t Rails 2 do this already?
Very nice!!
And yes, Rails 2 will do this … afaik, they’ve chosen to integrate Scott Becker’s AssetPackager, http://synthesis.sbecker.net/pages/asset_packager
I supposed I’d better go poke around in Edge Rails, and see how well it works. Until Rails 2, I’ll be using AssetPackager. But, for someone who uses packr, it’s certainly very handy to now have support for it. Should save you lot’s of time :)
Thanks for the link… Is the AssetPackager thing true? I’ve been using that for a while and it’s fantastic. I’ve been poking around on Rails Trac trying to find it but no joy – anyone know where in the source it is?
One difference between PackR and AP is that AP uses jsmin, which does not respect conditional comments. If you’re using those then using base62-packing (which rake packr:pack_libs does by default) before using AP to build scripts will keep them intact.
I was under impression that javascript_include_tag(:all, :cache => true) call in Rails2 only combines all js files but does not minify them. Core devs felt JSMin and similar approaches are not worth it in a world of gzip compression.
Agreed.. GZIP it. :)
Minify + gzip together is my preferred option. Smaller filesizes than just gzip. No overhead of doing eval() on every request as with packer.