Quick question: Packed or minified?

228 views
Skip to first unread message

Micky Hulse

unread,
Oct 19, 2008, 12:54:11 AM10/19/08
to SWFObject
Hi all,

I do not know how to tell the difference between packed/minified
code... So, just curious what swfObject uses?

Thanks!
Micky

Getify Solutions, Inc.

unread,
Oct 19, 2008, 1:22:58 AM10/19/08
to swfo...@googlegroups.com

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

--------------------------------------------------
From: "Micky Hulse" <rgm...@gmail.com>
Sent: Saturday, October 18, 2008 11:54 PM
To: "SWFObject" <swfo...@googlegroups.com>
Subject: Quick question: Packed or minified?

Micky Hulse

unread,
Oct 19, 2008, 3:40:49 AM10/19/08
to SWFObject
One word:

WOW

Thanks a billion for the excellent reply Kyle! Great info!

Great link too!

I have been using the below site for my compression needs:

<http://fmarcia.info/jsmin/test.html>

The link you provided is amazing though! Thanks!!!

Have a great day/night!
Cheers,
Micky

On Oct 18, 10:22 pm, "Getify Solutions, Inc." <get...@gmail.com>
wrote:
> From: "Micky Hulse" <rgmi...@gmail.com>

Aran Rhee

unread,
Oct 19, 2008, 7:25:46 PM10/19/08
to swfo...@googlegroups.com
Yeah, cheers for the detailed info Kyle. I did not know of the specifics of
YUI...

Aran

Bobby

unread,
Oct 20, 2008, 7:01:50 AM10/20/08
to SWFObject
Great piece Kyle :-)

The latest versions of YUI Compressor do respect IE conditional
comments, however these cause that the compression isn't optimal, so
that's why we still strip them out and put them back again.

Please also note that you can actually help Compressors to minify your
code better, by giving them code constructs that they can easily chew,
e.g. instead of using document.getElementById 15 times, reuse one
custom getElementById function that does just this one thing for you.

Getify Solutions, Inc.

unread,
Oct 20, 2008, 7:50:50 AM10/20/08
to swfo...@googlegroups.com
Another thing that's important for minifiers is to make sure your scripts
are as rock-solid as possible in terms of syntax. This doesn't really "help"
those tools, but it helps your script be more likely to operate the
same/properly in both the compressed and full states. JSLint
(http://www.jslint.com/) by Doug Crockford -- I've found to be a great a
tool in checking my scripts for lazy/poor style which can create issues for
the various compressors.

Disclaimer... this tool *IS* really picky, and as Doug says on his page, it
probably will "hurt your feelings" with what it complains about. I've never
had a script of mine COMPLETELY pass all its tests, but I often tweak my
scripts down to where there's only a few warnings that it gives, and in
doing so, I've never had a problem with my scripts failing to operate
identically after compression. It's just an extra step that takes some
effort and some learning to understand what JSLint outputs (some confusing
stuff you need to read his FAQ's about), but well worth it in my opinion.

One thing I love about this tool is that it actually interprets your
script's scoping usage, and lists all the different variables you use via
local, closure, global, etc. I often find variable misspellings this way,
because you can see all your variable names (at once, and per function) in a
simple list, and it even marks them if they've been used only once, or more
than once, to help you clue into problems.

Anyway, if you're writing a substantial amount of JS code in a library or
something, especially for others to use, it's very worthwhile.... if it's
just a few lines of custom code, it may be more of a hassle than necessary.

--Kyle


--------------------------------------------------
From: "Bobby" <bobbyvan...@gmail.com>
Sent: Monday, October 20, 2008 6:01 AM
To: "SWFObject" <swfo...@googlegroups.com>


Subject: Re: Quick question: Packed or minified?

>

Micky Hulse

unread,
Oct 20, 2008, 3:29:06 PM10/20/08
to SWFObject
Wow again!

Thanks all, great tips and info!

I love learning about ways that I can improve my coding. This: <http://
www.jslint.com/> sounds sweet! I would use that just to get tips on
how to write better JS. :)

Thanks all!!! :D

Have a great day.

Cheers,
Micky
Reply all
Reply to author
Forward
0 new messages