SlimIt 0.5 is out. This release includes name mangling that can be turned on with -m or –mangle flag from the command line.
To give you a taste of what it’s like here is a simple example:
function test() {
var long_name = 'long name', log = 5;
console.log(long_name);
foo = function(arg1, arg2) {
var arg2 = 'new arg2';
console.log(long_name + arg1 + arg2);
};
}
After name mangling:
function a() {
var a = 'long name', b = 5;
console.log(a);
foo = function(b, c) {
var c = 'new arg2';
console.log(a + b + c);
};
}
And here is a new jQuery 1.6.1 minification benchmark for jsmin, rJSmin, and SlimIt (the lower the better):
| jQuery 1.6.1 (bytes) | jsmin | rJSmin | SlimIt |
|---|---|---|---|
| 234,995 | 134,819 | 134,215 | 94,290 |
Please, file any bug reports at GitHub.
If you enjoyed this post why not subscribe via email or my RSS feed and get the latest updates immediately.
You can also follow me on GitHub or Twitter.



{ 9 comments… read them below or add one }
I have no idea if this is actually worth the extra effort, but with name mangling, you could use huffman coding to give the more frequently used symbols shorter names. It would only have an effect when you start having symbols with >= 2 characters in their mangled names.
Hi Peter,
Thanks for the suggestion.
There is an error in your mangled example, it make the a function un-recursable
If you add an actual recursive function call the name mangling should work as expected:
[sourcecode language="javascript"]
function test() {
var long_name = ‘long name’, log = 5;
console.log(long_name);
test();
}
[/sourcecode]
After mangling:
[sourcecode language="javascript"]
function a() {
var b = ‘long name’, c = 5;
console.log(b);
a();
}
[/sourcecode]
@DJ Gilcrease:
Looks fine to me… http://paste.pocoo.org/show/401566/
As you were already beating the other Python based minifiers so resoundingly, I thought I’d take a look at some other minifiers.
The official jQuery release uses the UglifyJS minifier according to https://github.com/jquery/jquery/tree/master/build/lib. The official minified release is 90,975 bytes (with the copyright header removed).
With http://marijnhaverbeke.nl/uglifyjs I get 90,985 bytes.
With http://closure-compiler.appspot.com/home I get 90,557 bytes.
Hi Laurence,
Those are tough competitors
Assuming foo name was not mangled becuase it is in the global scope it may be nice to have a –warn flag for globals similar to jslint. Good work though dood.
Hey Alex,
Thanks for the idea. You can also add it to issues so that I don’t forget