Script squashing
|
|
|||
|
|
Sign up to receive this and other networking newsletters in your inbox.
When I first started in the computer business I was an assembler programmer on ICL mainframes. In those days, the stakes were high, men were real men, women were real women and small furry creatures ... er, sorry, I've been reading "The Hitchhiker's Guide to the Galaxy " to my son...
Anyway, in those days, memory and disk space was at a premium. Indeed, those resources were at a premium until the mid-1990s.
Today, the idea of polishing software to save memory is considered an anachronism and as a result, bloated code is the order of the day. While it might be argued that given the nature of today's PCs code optimization to save space is a poor return on labor investment there is one area where shaving bytes can have a big payoff: Web pages.
If you use Macromedia Flash or Java applets the fact is that your target user either has a fast, fat pipe or really, really wants your content - shaving bytes is not crucial.
But if your target users expect a really snappy response or have limited bandwidth then adding JavaScript can be the only way of adding features without incurring an enormous overhead.
So, if you are going to use JavaScript and you want to maximize the user experience then optimizing your code is a really good idea - it will download faster and, in general, run faster. To this end there are several ways of shrinking your JavaScripts.
First, there's an ASP-style optimizer called JavaScript Compressor you can use for free from Creativyst (www.creativyst.com/Prod/3/).
You paste your code into the input window and the output window delivers the slimmed down code. The slimming down is achieved by removing white space, tabs and unnecessary carriage returns.
As of writing the optimizer doesn't handle one form of HTML comments ( "<!-- ... --> " – this is because this format is used to hiding JavaScript from browsers that can't support scripting) although the shortened forms ( "// " and "/* ... */ ") are recognized and removed. We got a reduction in code size of around 25% with JSC.
Next, we have a shareware application called JavaScript Scrambler from Quadhead (www.quadhead.de/) that compresses and scrambles your JavaScript making it harder for others to understand the coding. This tool runs under Windows 95, 98 and NT.
We couldn't try our large test script with this utility as the unregistered version is limited to scripts no bigger than 650 bytes, but a simple example achieved around a 25% reduction.
There are a handful of other JavaScript optimizers but most are outdated and the tools above do the job pretty well. As always, let me know if you've found a tool that you'd recommend.
Next issue we'll discuss another novel optimizer for Web content.
RELATED LINKS
Network World, 11/04/02
Mark Gibbs is a consultant, author, journalist, and columnist. He writes the weekly Backspin and Gearhead columns in Network World.
Mark Gibbs is a consultant, author, journalist, and columnist. He writes the weekly Backspin and Gearhead columns in Network World. Gibbs is also co-conspirator of the Vitally Important Information Web site.
Gibbs can be contacted at webapps@gibbs.com. Press releases to pr@gibbs.com.
