5

Browsers such as Chrome can only execute 6ish parallel requests.

If we attempt to simultaneously initiate more than 6 requests at once,

for (var i = 0; i < 11; 1++) {
  var oReq = new XMLHttpRequest();
  oReq.open('GET', URL);
  oReq.send();
}

then the browser will queue them up and execute them in batches of 6.

requests in browser

Is it possible to tell when a request had moved from the "waiting" state to actually being executed?

The onloadstart event seems to fire when the request is added to the queue rather than when it actually starts loading.

Community
  • 1
  • 1
David Tuite
  • 22,258
  • 25
  • 106
  • 176

1 Answers1

2

Have you looked about the readyState property of HttppRequest ? Maybe it will cover your question..

XMLHttpRequest Object Properties

readyState:

Holds the status of the XMLHttpRequest. Changes from 0 to 4:

0: request not initialized

1: server connection established

2: request received

3: processing request

4: request finished and response is ready

So using this info you could do something like this:

for (var i = 0; i < 11; 1++) {
  var oReq = new XMLHttpRequest();
  oReq.open('GET', URL);
  oReq.send();

  oReq.onreadystatechange = function(){
    if (oReq.readyState == 4 && oReq.status == 200) {   
      //do something like an alert
      //you can get rid of the oReq.status if you want and 
      //just track the readyState (0-4)
    };
  };
}
prieston
  • 1,426
  • 2
  • 18
  • 39