KevinDeus
KevinDeus

Reputation: 12178

Which is better? Multiple AJAX Requests or Requesting sets of data

So I have a page with several types of related data to be retrieved.

I can make 3 AJAX calls and split the data apart with the JQuery, (3 requests) or I can put additional AJAX calls in a loop in 3 places (150 requests).

Both situations pull back the same amount of data.

These are AJAX POSTs, but it could be done with GETs in other places.

On a simple level, Is one way better than another? Does it depend? Does it really matter?

Upvotes: 2

Views: 306

Answers (2)

SLaks
SLaks

Reputation: 887767

For better performance, you should make as few requests as possible.

However, if parts of the request will take longer for the server to retrieve, you should consider moving those parts to a separate request so that the rest of the request doesn't need to wait for it.
(Obviously, that will only help if you don't need those parts right away)

Upvotes: 5

Naftali
Naftali

Reputation: 146310

Well if you want less of a hit on your server, definitely do the one with less calls to it.

Upvotes: 2

Related Questions