Extremist Developer

RSS
Dec 9

Asynchronous JavaScript Loading

Last week i stumble upon a JavaScript problem, how to load a JavaScript asynchronously across all platforms. Usually i would just put the script tag at the bottom of my page to prevent any blocking, but in some case (advertisement) the script tag needed to be on the top.

The default script we were given looks like this :

The problem with this is pretty simple, it only behaves as a non-blocking loading in IE browsers, quite problematic when over 50% of your users are on other browsers. Looking at my stats, it turns out that pretty much anybody who doesn’t use IE as a browser that support HTML5, giving me access to the new async property for the script tag.

The new script (that works for IE and the rest) looks like this :