Speeding up AJAX Applications

Microsoft’s recent release of Doloto reminded me of the pain of the AJAX Programmer. Doloto is a tool for optimizing an AJAX application by analyzing its workload and splitting the code so that the application will start by transferring only the portion of code necessary to initialize. I can see many web programmers wanting to use it.

Although the Outlook web client has proved that it is possible to produce lightweight AJAX-based applications on the browser, last year’s report from Forrester Research confirmed the high level of disappointment with the performance of AJAX applications. Since then, Silverlight and Flex have somewhat improved the reputation of Rich Internet Applications (RIAs), but one cannot help but think that the disillusionment with AJAX was more due to the way in which the technology has been misused, than any intrinsic problem with the technology.

According to the Forrester report, there have been several problems, a few of which were, to some extent, out of the AJAX developers’ hands. For example, certain virus scanners investigate each line of JavaScript as it is run, thus degrading the rendering performance of the browser.

However, in other cases, poor implementation was to blame. Some AJAX applications were leaving all business logic, such as input validation, to the server to implement, requiring a roundtrip AJAX communication between the browser and server for each input field: up to 50 fields for a screen. In other cases, heavyweight frameworks were being used that required the loading of bulky JavaScript libraries and featured unnecessary animation and cute widgets. The worst problems seemed to be the transmission and parsing of bulky uncompressed XML data files.

One can, perhaps, blame some of the problems on the way that certain vendors implied that desktop applications could be easily ported to the browser, using DHTML and AJAX. Oh no. There are inherent limitations with browsers, and JavaScript has to be used abstemiously, with the respect required for a slower, usually interpreted, language. Even the X in AJAX, XML, proved to be a bottleneck when data sizes swelled. Web programming requires a different mindset.

Although one can remove some of the symptoms of framework-bloat by using Content delivery networks (CDNs) to deliver the bulky JavaScript frameworks, the best way of improving any AJAX application – almost any application in fact – is to measure, to profile, and to understand where the performance hotspots are.

Tools such as Firebug for JavaScript and ANTS Profiler for server-side assemblies allow you to collect as many metrics as you need in order to find out where the problems lie. You can then make an educated choice about where to focus your optimization efforts, concentrating on creating a good user experience, and cutting out both unnecessary database access and wasteful JavaScript routines. Before profiling tools arrived, web development was an uncertain art, with far less control than was enjoyed by .NET developers. With a lot of the uncertainty removed, perhaps we’ll soon see better use of the remarkable frameworks that exist for developing Rich Internet Applications.

Cheers,

Laila