2009/10/14

Different between Minfier and Packer

Found this article at
http://markmail.org/message/2v5mteddw3busgbp#query:packed%20vs.%20minified+page:1+mid:nfd2zt6ub3yltzgs+state:results


SWFObject uses YUI Compression (which is basically/similar-to minified, but with additional 'intelligence' to achieve smaller but still safe compression).

----------------------------------- Though it's a little off topic, for the benefit of the readership, here's a brief discussion of the differences:

YUI Compression (and minification) essentially strips out all whitespace/comments, shortens (safely) all internal variables, and removes unnecessary code syntactics.  The benefit is really good compression, but extremely quick "initialization" (in other words, having it ready on your page), because the code is directly executable in the page.

One other downside of YUI Compressor is that it strips out (or fails on, sometimes) IE-conditional-compilation comments, which SWFObject uses.  So, SWFObject's authors actually remove the IE-conditional-compilation block, YUI compress the code, then add the block back in, adjusting it to the right minified variable names, etc.  Kind of a pain, but this produces the best result (see below).

Packing (like Dean Edwards' Packer, among others) uses a slightly different concept -- it actually applies an advanced set of 'compression' packing algorithm to the code, rearranging code blocks/commands, using techniques to take advantage of looping, etc... and then it tacks onto the end a small runtime that 'unpacks' the payload and passes it through an eval() statement to evaluate it for execution on the page. Some 'packers' even actually use real compression, like zip or gzip, with javascript implementations of the decompressors.  The benefit is much higher compression, but the tradeoff is that the "decompression"/evaluation actually has some performance cost, sometimes a few seconds worth, for it to initialize and be ready for the page to use.

One additional factor is that a server can apply gzip/deflate compression on the stream of text being sent to the browser, so a 'minified' script can be 'compressed' with gzip (usually on the fly) for transfer over-the-line, and the browser takes care of natively uncompressing it.  This type of compression has much less performance cost.  The main downside is that the server (and browser, which most modern ones do) must support gzip compression.

Generally speaking, for most scripts, YUI compression (minification) combined with server/browser-gzip transfer turns out to be the best combination -- it generally gets the best, most efficient "compression", because it achieves close to (or better) compression to 'packers', but without most of the runtime performance cost.

In fact, this URL will take any script and run it through several of the most common minifiers/packers/compressors, and their various configuration tuning options, and return a list of all combinations with size and runtime speed costs. It sorts the list so you can see the best choice for your script.  http://compressorrater.thruhere.net/

Hope that helps.  :)

--Kyle

No comments:

Post a Comment