Which is better? Multiple AJAX Requests or Requesting sets of data
So I have a page with several types开发者_JAVA百科 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?
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)
Well if you want less of a hit on your server, definitely do the one with less calls to it.
精彩评论