In my application, the client initiates multiple asynchronous JavaScript requests to third party servers. The issue I'm encountering is that when the client responds to these requests, the site becomes inactive for a brief period of time. This inactivity is multiplied with each subsequent request, resulting in overall inefficient loading times. For example, if x number of requests are sent and the average downtime per response is y milliseconds, then the total inefficiency can be calculated as x*y. I am looking for ways to consolidate these calls into a single one. Some of the third-party services I make calls to include Google Analytics and Google Ad Leads.
Here's an example of one of the calls I currently use:
function () {
var oldonload = window.onload;
window.onload = function(){
__adroll_loaded=true;
var scr = document.createElement("script");
var host = (("https:" == document.location.protocol) ? "https://s.adroll.com" : "http://a.adroll.com");
scr.setAttribute('async', 'true');
scr.type = "text/javascript";
scr.src = host + "/j/roundtrip.js";
((document.getElementsByTagName('head') || [null])[0] ||
document.getElementsByTagName('script')[0].parentNode).appendChild(scr);
if(oldonload){oldonload()}};
}());