Unlike almost every other programming environment, javascript has one big drawback: you have to deliver it to the client. This can result in a big payload of code you’re dropping on your user and there isn’t a whole lot you can do about it.

You can lazy load the javascript so it’s only on demand. You can optimize your code as best you can so that functionality that’s not really needed isn’t present, and other functionality is written as succinctly as possible. You can set up your server to deliver the javascript g-zipped if the browser supports it.

But one simple thing you can do is just delint your code - remove all the tabs and comments and line breaks. It makes for unreadable files, but you just keep a marked up version and a compressed version. For example, Andy Lottmann took the prototype library and knocked it down from 55K to 35K or so.

I’m getting ready to release the history toolbar application that some of you have seen and the libraries total a whopping 93K if you don’t count Prototype. That’s will all my comments and indentation and the like.

I used this simple web-based javascript delinting tool on my files and got that down to 63K, which isn’t so bad. Add to that that I’m lazy loading all but 7K of that and the footprint of my code is really light (until it executes).

My toolbar shows you the most recent products you’ve viewed and does a bunch of nifty animated and ajaxy things. The first thing it does is hit the (new) RTSS server to see if you have a history. If you don’t, my code stops and you don’t get any more code. The only impact you’ve seen is 8K of javascript that didn’t really do anything visible. If you do have a history, it goes and fetches the rest of it, but this is happening after everything else on the page has already been fetched, so the impact on your experience should be negligable.

Additionally, I took Andy’s version of Prototype (and added the onDOMReady extension) and upgraded the version that was in place (ver. 1.4). Andy’s version, which is also delinted, is 35K, while the 1.4 version, which wasn’t delinted, was 46K (Andy’s version is 1.5, which includes additional functionality and therefore weighs in at 55K before delinting). So I saved 11K there, which makes the cumulative impact of my history toolbar negative until you have a history, and then, when you do, makes the cumulative impact about 52K more than before.

This could be lightened even more if we switched to Prototype.lite, which is only 8K delinted, saving an additional 25K. But we can’t do that without refactoring the universal login component and the My Products components to use moo.ajax. But that’s another story.