When I make simultaneous API calls using Ajax, the process seems to be slow as JavaScript waits for all API responses instead of fetching them asynchronously.
For instance, /api/test1 usually responds in 5 seconds and /api/test2 also responds in 5 seconds. However, when both are called simultaneously, it takes 10 seconds to complete.
To illustrate, the combined call takes 10 seconds:
$.get("/api/test1", function() {
self.responseHandler1();
});
$.get("/api/test2", function() {
self.responseHandler2();
});
In order to speed up the process, I have been implementing the following approach:
$.get("/api/test1", function() { // 5 sec
self.responseHandler1();
$.get("/api/test2", function() { // 5 sec
self.responseHandler2();
});
});
If you have any suggestions or a better solution for handling multiple API calls more efficiently, please advise me.