1

I would like to know if the browser batch huge number of ajax requests to a single server. I'm using jQuery and sending approx. 300 requests to server at a time. When I look at the firebug console, it appears as if the requests are going in batches. Is this done by jQuery or browser?

EDIT: I understand that browser has a limit on maximum number of simultaneous connection to the server. Questions is can I rely on the browser to handle huge number of requests or I've to implement some queue for processing requests (say 5 requests at a time)

hanish.kh
  • 517
  • 3
  • 15
  • It's done by the browser. It's not that it batches request, it's just that it has a maximum number of contemporary connections, so it looks like it's batching them – Jonas Grumann Jul 04 '14 at 15:03

3 Answers3

3

The browser has no way of grouping the AJAX requests into a single "batch" request, the server wouldn't know how to handle it. It will certainly buffer the requests, so that only two or so requests are processed at a time.

I'm using jQuery and sending approx. 300 requests to server at a time.

I hope you don't intend to do this in production. It would probably be better to programmatically batch process many things together.

Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171
  • Thanks Alexander, I mean buffer :). Sorry for the bad English. I got your point, but if the browser buffers requests and processes a number of requests at a time then why do I have to use a batching mechanism? – hanish.kh Jul 04 '14 at 15:12
  • It would greatly reduce your server and client load. There is a fair amount of overhead to each HTTP request. The more data you get per request, the less repeated data from things like HTTP headers you will receive. – Alexander O'Mara Jul 04 '14 at 15:16
1

The browser does limit the requests to a limited number of paraller request so it may appear that it is happening in batches. Garrett explains this better here How to perform Ajax requests, a few at a time

While with JQuery can also help in batching requests yourself using a "future" like method called $.when() that expects a few promises to be resolved, in this case your ajax requests see Guillaume86 explains this here jQuery.when understanding.

Sorry that I'm not answering directly but this topics are well explained on the two Questions I referred to. Cheers.

While technically I answer your question, practically as Alexander said, it's good practice to try to minimise your client / server interactions to the minimum possible.

Community
  • 1
  • 1
  • Yes. The first link answers my question. It says we can rely on the browser for handling parallel queries. – hanish.kh Jul 04 '14 at 15:14
0

You can make the requests faster by settings header Connection: Keep-Alive;. Then the browser does not need to create new connection for every request.

But still it would be better to make server API that support some kind of batch.

e.g. for JSON-RPC:

{method:'batch.process', params: [{method:'...'},{method:'...'},...]}
Radek Pech
  • 3,032
  • 1
  • 24
  • 29