There and Back Again

AJAX and Latency

So i just saw a great piece by Harry Fuecks on how latency can effect AJAX requests. Its one of his demo’s from the ajax@localhost presentation he gave at the PHP Conference Uk.

Now this showed a number of interesting problems, and while HTML_AJAX does a bit better then some toolkits it doesn’t handle them all. However thanks to HTML_AJAX’s design it not that hard to work around some of them.

So to that extent here is a really simple livesearch demo that keeps the reponses in the same order as the requests. The server is adding latency for you so you don’t need to worry about setting up a proxy to try it out. This is only available from HTML_AJAX svn right now, but we should do a release in another week or so there are lots of other good fixes in it.

Please note this queue isn’t really all that great for livesearch (ie it pounds your server). The current queue that is recommened for livesearch (and the one that HTML_Quickform_Livesearch (demo on my server, not the final version) uses sends a request at a maximum rate of every 350ms (this rate is configurable) instead of per character typed.

Finally this is just a quick hack, if you set the latency up too about 10 seconds you’ll start hitting some bug in the timeout code. The timeout is getting combined amoung multiple elements or something. The JS code might be really leak happy too, the queue doesn’t actually have all that much control of what happens when a request is complete just in when it sent in the current design. So to get around this i replace the users callback with one in the queue, and then do some closure fun. And here is the new queue code if you want to take a look.

One thought on “AJAX and Latency

  1. Pingback: SitePoint Blogs » Two kinds of AJAX: HTML++ vs Client / SOA