NYCPHP Meetup

[nycphp-talk] So why is Ajax so fast?

Dan Cech dcech at phpwerx.net
Fri Jan 12 10:21:56 EST 2007


Kenneth Downs wrote:
> We've all seen the amazing results you can get when you start using
> Ajax, they all come down to one thing: speed.
> 
> Question is, how is such a speed-up accomplished?  The standard answer
> is that a complete trip to the server is averted, but this is not true,
> in fact a complete cycle does occur:
> 
> 1)  Request to server
> 2)  Possible db access on server
> 3)  rendering of HTML on server
> 4)  delivery to browser
> 5)  re-rendering of portions of screen

The simple answer is that each ajax request is usually much more
lightweight than a complete page refresh.  You're avoiding the overhead
of re-generating all the surrounding content on the server, sending it
to the client and rendering it in the browser.

As an example, a simple pair of linked select boxes.  The category the
client selects in the first will change the items available in the second.

1. Traditional Method

When changing the first select box, the form is automatically submitted
the server, which then renders a complete new page (based on the
selected category) and sends it to the client.  The client then displays
the updated page.

2. Ajax Method

When changing the first select box, javascript requests an updated list
of items from the server, which generates the list and sends it to the
client.  Javascript then repopulates the second select box.


So we've done less work on the server, transferred less data and saved
time on the client, by reloading only a fraction of the data on the
page, rather than the whole thing.

Dan



More information about the talk mailing list