0

Problem that I'm trying to solve:

I have two arrays of ajax functions.

var topPriorityAjaxCalls = [ajaxCall1, ajaxCall2, ajaxCall3];

var minorPriorityAjaxCalls = [ajaxCall4, ajaxCall5, ajaxCall6, ... , ajaxCall10];

The first set of ajax calls(topPriorityAjaxCalls) have TOP priority because the information obtained by these calls are need it as soon as the user loads the page.

The second set of ajax calls(minorPriorityAjaxCalls) will also obtained information that I want to show to the user, BUT the information is hidden when the user loads the page (the accordions are closed).

In order to give priority to my first set of AJAX calls, is it enough to start them first? Will all of the browsers respect the order in which I call these functions?

Note: I understand that the responses from the server will be asynchronous, since A in AJAX stands for that.

Cacho Santa
  • 6,846
  • 6
  • 41
  • 73

1 Answers1

1

Yes, all browsers will initiate requests in the order your code initiates requests.

That doesn't mean that the network will prioritize them, or that they will finish faster than requests initiated later, but it's the most you can do.

user229044
  • 232,980
  • 40
  • 330
  • 338
  • thanks @meager! Good to see you again :D One more thing before I conclude this, do you have any recommendation if I really need to be done with the topPriorityCalls[ ]; first. – Cacho Santa Feb 25 '15 at 15:36
  • 1
    @cacho use `$.when.apply($, topPriorityAjaxCalls)` to synchronise anything that depends on those being finished first. You may wish to defer starting the low priority calls until then so that they don't overload the server that'll be busy servicing the top priority calls. – Alnitak Feb 25 '15 at 15:38
  • but nothing really depends on the first 3 calls, I just want to finish them first so the user will see all that information quickly. – Cacho Santa Feb 25 '15 at 15:39
  • 1
    @cacho Then just initiate them first. Look, what you're continually saying makes no sense. If you want to finish them **first**, then **just do them first**. Use `$.when`. Just using `$.when` doesn't mean that the later calls depend on the earlier calls, as you keep replying every time somebody suggests `$.when`. It doesn't matter whether the low-priority calls depend on the high-priority calls, `$.when` is still the correct way to order one set before the other. Otherwise, just make sure they're invoked as early as possible and that the server responds to them quickly. – user229044 Feb 25 '15 at 15:50