
Do you train Kung Fu?
Or know someone who does?
Then check out KungFuPeople.com
Mobile version of this pagePython Code Dojo London - 17 Sep 2009
Next:
My first Twitter app - KungFuPeople.com
Related blogs
Comparing YUI Compressor and slimmerThe awesomest way possible to serve your static stuff in Django with Nginx
Comparing Google Closure with UglifyJS
Related by category
Comparing jsmin and slimmer
17th of September 2009
JSMIN - The Javascript Minifier is written in C and it does an excellent job of minifying Javascript code. After all, Douglas Crockford wrote it. I noticed there's a Python implementation of it so I wanted to see how it stacks up against my slimmer which is also written in Python.
For sake of argument I compiled the C version and ran that in my little benchmark and did so by using the subprocess module. Also, for the sake of comparison I threw in a run with YUI Compressor. Here are some quick results:
On js/signup-core.js -------------------- js_slimmer from 9708 to 6905 in 0.0245039463043 seconds jsmin from 9708 to 6720 in 0.0850019454956 seconds jsmin.c from 9708 to 6721 in 0.0026159286499 seconds yuicompressor from 9708 to 6102 in 0.914173126221 seconds On js/zoom.js ------------- js_slimmer from 5920 to 3712 in 0.0106379985809 seconds jsmin from 5920 to 3582 in 0.0582370758057 seconds jsmin.c from 5920 to 3583 in 0.00282216072083 seconds yuicompressor from 5920 to 2771 in 0.839382171631 seconds On js/diypack.js ---------------- js_slimmer from 21559 to 14059 in 0.0409741401672 seconds jsmin from 21559 to 13655 in 0.177556037903 seconds jsmin.c from 21559 to 13656 in 0.00346994400024 seconds yuicompressor from 21559 to 11638 in 0.891603946686 seconds
So, roughly, slimmer is 4 times faster than jsmin.py but fails to minify a couple of bytes. jsmin.c is about 6 times faster than slimmer.py but is awkward since it's in C. I guess jsmin.c is the way forward when you want speed and the best result. slimmer has the advantage of being all in python and PyPi and contains functions for CSS, HTML and XHTML as well.
It's clear the YUI Compressor does a wicked job at minifying but by running a .jar file every time in a subprocess is crazily slow if that matters for you.
Comment
But in net effect YUI Compressor rocked your socks, seeing as the speed makes very little difference when you have server-side caches.
Or as I do with one project, simply have a *compile* step in your deploy -- we extract JavaScript translations into a static file at that stage as well, and compress that. It's really neat!


Sure, YUI Compressor is slow and requires Java, but it's safe; thanks to Rhino.
jsmin is fine to compress your own, well written, javascript files; you just need to check them with jslint to be sure nothing will break. But if it's some else work, you cannot fork it just so that it passes jslint checks.