There are several techniques that can help us properly mixed well in every situation, the most interesting of these is the asynchronous loading of the script to get around the blocking nature of the tag script. Although the latest versions of browsers to make available tools such as Web Workers, their limited support (blank in IE) has forced developers to implement alternative solutions. Other than that it should be noted that the Web Workers, just the kind of background processes can not interact with the DOM of the document needs to operate more. Today, a proven technique to bypass the blocking nature of the tag script is to dynamically inject the script in the document. A simple implementation of this strategy is as follows:
Code:
addScript function (src) {
var tag = document.createElement ('script');
tag.src = src;
tag.type = 'text / javascript';
document.getElementsByTagName ('head') [0]. appendChild (tag);
}
As is easy to understand, losing their character blocking scripts loaded in this way will not be processed in order, so dependencies are not met. The best solution then is to rely on libraries that implement a system of dependency. In the framework of the family found a system of dependency in Dojo, YUI and Google Closure, but initially we will consider two solutions standalone LABjs and RequireJS.
Bookmarks