Reasonable amount of concurrent ajax asynchronous requests

I am wondering what is the opinion of how many simultaneous asynchronous ajax requests are usually valid.

I ask, I am working on a personal web application. For the most part, I support my requests up to one. However, there are several situations where I send up to 4 requests at a time. This causes a slight delay, as the browser will only process 2 at a time.

Delay is not an issue in terms of usability. And there will be some time before I worry about scalability, if ever. But I try to adhere to best practices, as far as reasonable. What do you think? Is 4 queries a reasonable number?

+5
source share
5 answers

It really depends on whether it works like that. If the application logic is built in such a way that it makes sense to execute 4 simultaneous requests, do it like this. If the logic is not broken by packing several requests into one request, you can do it, but only if it does not make the code more complicated. Keep it as simple and straight forward as you have problems, then you can start optimizing.

But you may ask yourself if you can improve the design of the application so that it does not require several requests.

. HTTP , . , .

+2

, , .

Firefox, about:config network.http.max-connections-per-server, . , AJAX. , IE 2. Chrome Opera.

Edit:

Firefox 23 network.http.max-connections-per-server , network.http.max-persistent-connections-per-server, - 6.

+4

, . , 4 , 20 - . , . - .

- . Fiddler , , (56K ).

, , , . , .

+2

, , , , , , , . , . , .

var request = []//a queue of the requests to be sent to the server

request[request.length] = //whatever you want to send to the server
startSend();

function startSend(){//if nothing is in the queue go ahead and send this one
  if(request.length===1){
    send();
  }
}

function send(){//the ajax call to the server using the first request in queue
  var sendData = request[0];
  //code to send the data
  //then when you get the response (I can't remember exactly the code for it)
  //send it to a function to process the data
}

function process(data){
  request.splice(0,1);
  if(request.length>0){//check to see if you need to do another ajax call
    send();
  }
  //process data
}

, , , , , , , 2 . , , , , , . . , . , .

0

1 - , , , .

, IE , 2. , , 2 , , . " script " IE.

, 4 ( IE, JavaScript), , , , .

0

All Articles