AJAX - The Complete Reference

(avery) #1

258 Part II: Developing an Ajax Library^


Then bind a script to stop the timer upon full page load to calculate how long it took:

window.onload = function ()
{
var pageEndTime = (new Date()).getTime();
var pageLoadTime = (pageEndTime - gPageStartTime)/1000;
alert("Page Load Time: " + pageLoadTime);
}

Ajax or any other JavaScript communications mechanism could be used to transmit the
user’s connection data back to the server for statistical purposes.

NNOT EOTE Internet Explorer supports a feature called Client Capabilities that can easily be used to
determine if a user is on a LAN or dial-up connection. However, because it is so browser specific
and does nothing in terms of determining actual connection rate, it is not discussed in detail here.

Rather than measure the page itself, it might be more interesting to make a number of Ajax
requests with a set amount of content and measure how long the requests take to come from
the server on average. A simple example “Connection Rate Explorer,” shown in Figure 6-16 at
http://ajaxref.com/ch6/connectionspeed.html, does exactly that.
Any connection profile information gathered could then be sent to the server for statistics
or used to guide future decisions, including potentially falling back to a non-Ajax solution or
focusing on improving the performance of the server or application.

Tracking Network Conditions


As requests are made, the experience should be tracked. For example, it is likely a good idea
to keep track of page level communication counters such as number of requests made,
number of requests failed, number succeeded, number of timeouts, and number of retries.
Details on the failed requests also should be collected for later forensics.

FIGURE 6-16 Connection speed measurements with Ajax
Free download pdf