Return to Snippet

Revision: 16199
at July 28, 2009 18:09 by iTony


Initial Code
function loadScript(url, callback){

    var script = document.createElement("script")
    script.type = "text/javascript";

    if (script.readyState){  //IE
        script.onreadystatechange = function(){
            if (script.readyState == "loaded" ||
                    script.readyState == "complete"){
                script.onreadystatechange = null;
                callback();
            }
        };
    } else {  //Others
        script.onload = function(){
            callback();
        };
    }

    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
}

Initial URL
http://www.nczonline.net/blog/2009/07/28/the-best-way-to-load-external-javascript/

Initial Description

                                

Initial Title
Loading Scripts without Blocking

Initial Tags

                                

Initial Language
JavaScript