AJAX - The Complete Reference

(avery) #1

246 Part II: Developing an Ajax Library^


Browsers typically don’t pull requests in an unpredictable way, but if you wanted to be
very strict about the ordering of requests, it would be easy enough to create a request queue.
Given that the native queue preserves order, you might wonder why such a request queue is
useful. Consider that timeouts could be applied more logically with such a queue, in other
words the timeout counter wouldn’t be started until the queued request was actually sent.
With this in place, situations, such as the one seen in Figure 6-8 where slow requests in
progress cause waiting requests to timeout, would not occur. However, you may argue that
you want timeouts to work this way since the time passing is the same to the user. There is
simply no best answer here and readers will have to decide which approach to take.
The idea of the request queue would be to take each request and put it in a queue so
that the code could send it when desired and in order. In the sample library, it is possible to
create requests in the form of a URL string and an options object and add it to the queue
using the method AjaxTCR.comm.queue.add(url,options). As a demonstration, the

FIGURE 6-8 Requests are going out in the order queued
Free download pdf