Adventures in Packing, Minifying, gzipping and iPhoning

I have a few days to kill before we officially start selling Shockey Monkey v2 (waiting on Windows Mobile application to be completely bugless) and I figured I'd sit down and work on Shockey Monkey performance a little.

Good news. No page under Shockey Monkey requires more than 1 second to render, with most actually rendered in under 0.3 seconds.

The network utilization is a whole different story unfortunately. You see, all the pretty AJAX interface and usability functionality comes at a cost. Roughly 400 Kb worth of uncompressed Javascript type of a cost. To give you an idea of why this is a problem: imagine refreshing the support request display give times. You would have downloaded 2 Mb worth of Javascript. Not good at all.

So one of my tasks this weekend was to figure out a way to reduce that burden. The first problem was that of multiple requests. Between my own and third party Javascript I had eight Javascript files, meaning eight requests to the web server. Since IE and Firefox only use a maximum of two requests to the server this meant that the browser would request, load, request, load, request, load... and make you pull your hair as you watched the loading bar bounce around.

I first started with trying to combine my Javascript on the fly which resulted in a learning experience that packed Javascript code cannot be combined. FMR.

I finally ended up uncompressing all of my Javascript and minifying it in a single Javascript file. Here is the before:

packitup

Notice it took nearly a second for the combined request to pull down all my Javascript files. But with minification and a single script:

afterminify

Notice that after minification and consolidation the Javascript library has gone from over 400 uncompressed, to 340 compressed, down to 142 compressed and minified! The total download and render time from nearly a second down to 1/5th of a second! If I put my marketing hat on, that's 500% improvement!

So a page with 168 support requests, live code and effects including autocomplete and all the other good stuff is yours in 2.38 seconds.

I have two items remaining in the to do list. First, enable gzip compression on the server even more. Second, find out why Javascript is not being cached. Currently I am trying to cache Javascript code at 1 month:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType application/x-javascript "access plus 1 month"
</IfModule>

But not making it very far with that one, yes the module is loaded and available.

As far as the iPhone is concerned - app works flawlessly over Safari even the visual effects are all there. As for release, any day now folks...

4 comments on “Adventures in Packing, Minifying, gzipping and iPhoning”

  1. JavaScript - secured and compressed or secured and cached. All three don't work reliably (can't remember if compressed and cached works - it's been a while).

    Caching of secured objects only works with browser buy-in (Save encrypted pages to disk).

    I vaguely remember getting all three going by using a different extension for the JavaScript and changing the MIME Type for this to text/plain. I'll see if I can dig up the source code/notes to the project and find out what I did.

  2. OK, got it.

    ExpiresByType application/x-javascript A2592000

    which should do the same as what you've got above. This is the geek version :-)

    I also wasn't compressing .css nor .js - the trade-off was having caching enabled. The problem I encountered was that compressed .css/.js wouldn't cache in IE6, no matter how much I tried.

    This is going back 4 years though. Things may have changed since then.

  3. vlad says:

    I like something that is more maintainable, thank you very much :)

    Minifying is not the same as compressing, all it does is remove newlines, comments and other junk. There is another process out there called packing which does all the other cool stuff including shrinking variable names and so on and so forth.

    I'm letting the server handle the compression, enabled gzip as an encoding on the entire server.

    Still, unable to get the Javascript to cache. I'm actually very close to just changing the .js mime type to php so I can send custom expires to those requests....

    -Vlad

  4. The .js and MIME type flip was during the dev phase to try and figure out was was going on. It never reached production for the same reason you mention.

    Minify makes a bigger difference than packing, especially if you run the resultant .js through mod_gzip/mod_deflate.

    Quite a few of the .css compression methods out there wrap CSS in PHP, so that process might also work well with JavaScript. ob_gzhandler + Expires headers might do the trick. But I still reckon it's a browser "feature" you're running into. I'd like to be proved wrong though.

Historical discussion. New comments are closed for this post.