Segway Gran PrixIn a common theme from JavaOne, it appears you need to be spruiking a product to get a gig as a presenter, so I was almost lulled into a false sense of security when I went to a session on AJAX performance.  The presenter went through some interesting aspects of AJAX performance, and I will highlight them here.

Reducing Start-up Time
The main aspect for AJAX is the size of the JavaScript file.  There was a discussion about how to reduce the size via a number of methods such as combining your files into a single file since this is more efficient (fewer HTTP requests which are expensive).  You can do this by creating a servlet that combines you different files on the fly, or use the development environment to build the combined file.  The Dojo toolkit was recommended as a way to do the build time version, since it can handles issues like script dependencies for you.

In addition, you can reduce start-up time by making the file smaller by removing white space and comments.  There are some tools that can do this (Dojo, safe compress), with the major caveat that you need to ensure all lines end with a semicolon since these tools remove the carriage return and some script relies on carriage return to indicate the end of the line.

Finally, if the file can be gzip’d then this will also reduce the start-up time.  Most newer browsers can support this (HTTP 1.1 with stated gzip support), but you will probably need some client and server script to detect the browser and see if you can provide the compressed version.

(He also suggested distracting the user with flashy graphics, but I don’t think that is a technical approach –  leave that to the Project Manager to suggest)

Reducing Run Time
There were a few technical hints to speed up actual code (such as using native DOM parsing in the browser, that string comparisons in IE are 4 times slower than Firefox) but at this point the presentation mostly turned into the product spiel for jsLex (darn!  another spruik) which will help you run tests against your code and identify poor performance areas.  This seems to be pretty helpful, and is probably worth a look if you need to optimise AJAX code.

Overall, it was interesting the the combination and compression of the JavaScript files seemed to be very important.  After that it comes down to ‘normal’ code optimisation and in that situation a tool is always going to make that easier.

Written by Mark Johnson

Mark Johnson is one of the Directors of Shine Solutions Group, a Technology Consultancy in Melbourne, Australia.

One comment

  1. I would have enjoyed this presentation. Just spent a good part of my evening monitoring AJAX related HTTP requests on Tangler. Problem is we are using all of the recommend techniques highlighted above but speed it still an issue.

    I would also add that CSS can add wieght to the page, so using a combiner servlet and compressing CSS can help.

    Cache is also a big one, configuring the correct cahce settings in the HTTP response headers will dramatically increase subsequent page loads.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s