Thursday, October 18th, 2007

PackR: Rails Packing

Category: JavaScript, Rails, Utility

James Coglan has produced a Rails plugin to handle Dean Edwards Packer.

PackR allows you to programatically compress:

  1. # Create a new instance of Packr first
  2. packr =
  3. compressed = packr.pack(script)
  5. # Pass options to control the type of compression
  6. compressed = packr.pack(script, :shrink_vars => true)
  7. compressed = packr.pack(script, :base62 => true)
  8. compressed = packr.pack(script, :shrink_vars => true, :base62 => true)

or you can use the rake task:

rake packr:pack_libs

Posted by Dion Almaer at 6:26 am

2.3 rating from 34 votes


Comments feed TrackBack URI

Doesn’t Rails 2 do this already?

Comment by Alex MacCaw — October 18, 2007

Very nice!!

And yes, Rails 2 will do this … afaik, they’ve chosen to integrate Scott Becker’s AssetPackager,

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 :)

Comment by Morgan Roderick — October 18, 2007

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.

Comment by James Coglan — October 18, 2007

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.

Comment by Mika Tuupola — October 18, 2007

Agreed.. GZIP it. :)

Comment by Alexei — October 18, 2007

Minify + gzip together is my preferred option. Smaller filesizes than just gzip. No overhead of doing eval() on every request as with packer.

Comment by Mika Tuupola — October 19, 2007

Leave a comment

You must be logged in to post a comment.