Skip to content Skip to sidebar Skip to footer

Detecting And Terminating Slow Third Party Javascript Requests

We're using number of Tracking Pixels on our website to gather stats about our visitors. However, often some of those third party javascript that we embed in code are waiting on a

Solution 1:

You can load the scripts using the cache instead:

var scriptTag = document.createElement("script");
scriptTag.type = "text/cache";
scriptTag.src = "http://thirdparty.com/foo.js";
scriptTag.onreadystatechange = scriptTag.onload = function() {
    if (scriptTag.readyState == "loaded" || scriptTag.readyState == "complete")
    {
        // it's done loading
    }
}

This will cause the scripts to load in the background like an image; you can then call them directly if they load. The caveat is that if you have several that time out it can consume all of the available outgoing connections. If you serialize the 3rd party Javascripts only then they should at most consume one connection.

This is the technique used by head.js. You can probably just use head.js, but you may want to add some extra logic for what to do with timeouts and so on.

Post a Comment for "Detecting And Terminating Slow Third Party Javascript Requests"