The If Works This dirt was a building before

PackR 3.1: improved compression and private variable support

Dean Edwards recently released version 3.1 of Packer, his JavaScript compression tool. You’ll be pleased to know I’ve been keeping up with development, and I’ve just released PackR 3.1. PackR is a Ruby version of Packer that can be used from the command line or within Ruby apps.

sudo gem install packr

This release improves compression of local variable names, and adds a couple new features. Firstly, it allows you to compress private variables (denoted by a leading underscore), meaning you can clearly indicate that private methods should not be called as they will have unpredictable numeric names once packed:

Packr.pack("foo._someMethod();", :private => true)
# => "foo._1()"

Secondly, it allows you to protect certain variables from compression. For example, Prototype uses the magic $super variable to implement inheritance, so your code will break if that variable is renamed. You can prevent this by telling PackR to ignore it:

Packr.pack(code, :shrink_vars => true,
                 :protect => ['$super'])

Finally, note that PackR is now a gem and not a Rails plugin. Obviously this means you can still use it in Rails, you just need to install it differently.

Give it a spin and let me know how it goes. Any bugs should be reported to me at Github.


2 Comments

Looks great, thanks a lot. BTW have you considered releasing the gem via GitHub?

Posted by Gianni Chiappetta on 2 March 2009 @ 10pm

[...] that’s an extension to allow you to do whatever you want. In this example, we’re using jcoglan’s Packr library to automatically pack our generated Javascript. This can result in filesize being reduced by pretty [...]

Posted by Coffee Powered » Sweet-ass performance hacks: better_assets on 29 July 2009 @ 10am

Leave a Comment