Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A reasonable number of simultaneous, asynchronous ajax requests

I'm wondering what the consensus is on how many simultaneous asynchronous ajax requests is generally allowable.

The reason I ask, is I'm working on a personal web app. For the most part I keep my requests down to one. However there are a few situations where I send up to 4 requests simultaneously. This causes a bit of delay, as the browser will only handle 2 at a time.

The delay is not a problem in terms of usability, for now. And it'll be awhile before I have to worry about scalability, if ever. But I am trying to adhere to best practices, as much as is reasonable. What are your thoughts? Is 4 requests a reasonable number?

like image 304
Travis Avatar asked Jul 12 '10 17:07

Travis


People also ask

How many AJAX requests are there?

By default, the JavaScript Agent limits the Ajax requests (using XHR or the Fetch API) sent for base or virtual pages. The limit is 250 requests for single-page applications (SPAs) and 50 for non-SPAs.

Can we execute run multiple AJAX requests simultaneously in jQuery?

To iterate through the response, there is a callback function attached to it. This callback function gets executed once both the Ajax requests are finished. In case where multiple Deferred objects are passed to $. when() , it takes the response returned by both calls, and constructs a new promise object.

What is asynchronous request in AJAX?

Asynchronous (in Ajax) processes incoming requests in a constant event stack and sends small requests one after the other without waiting for responses. In other words, asynchronous ajax call allow the next line of code to execute, whereas synchronous call stop JavaScript execution until the response from server.

What is AJAX used for when working with asynchronous requests?

Ajax is a technology that allows developers to make asynchronous HTTP requests without the need for a full page refresh.


2 Answers

I'm pretty sure the browser limits the number of connections you can have anyway.

If you have Firefox, type in about:config and look for network.http.max-connections-per-server and that will tell you your maximum. I'm almost positive that this will be the limit for AJAX connections as well. I think IE is limited to 2. I'm not sure about Chrome or Opera.

Edit:

In Firefox 23 the preference with name network.http.max-connections-per-server doesn't exist, but there is a network.http.max-persistent-connections-per-server and the default value is 6.

like image 161
Andir Avatar answered Nov 15 '22 00:11

Andir


That really depends on if it works like that properly. If the logic of the application is built that 4 simultaneos requests make sense, do it like this. If the logic isn't disturbed by packing multiple requests into one request you can do that, but only if it won't make the code more complicated. Keep it as simple and straight forward until you have problems, then you can start to optimize.

But you can ask yourself if the design of the app can be improved that there is no need for multiple requests.

Also check it on a really slow connection. Simultaneous http requests are not necessarily executed on the server in the proper order and they might also return in a different order. That might give problems you'll experience only on slower lines.

like image 21
Christian Avatar answered Nov 15 '22 00:11

Christian