JSFiddle - React, Tailwind, and code Playground

by jfriend00

HTML

<div id="test"></div>

JavaScript

function loadScriptsInParallel(scripts, completeCallback) {
    var head = document.getElementsByTagName('head')[0];
    var remaining = scripts.length, i, scriptTag;
    
    function complete() {
        // make sure it's not called again for this script
        this.onreadystatechange = this.onload = function() {};
        // decrement remaining count and check if all are done
        --remaining;
        if (remaining === 0) {
            // all are done call the callback
            completeCallback();
        }
    }
    
    for (var i = 0; i < scripts.length; i++) {
        scriptTag = document.createElement('script');
        scriptTag.type = 'text/javascript';
        scriptTag.src = scripts[i];
        // most browsers
        scriptTag.onload = complete;
        // IE 6 & 7
        scriptTag.onreadystatechange = function() {
            if (this.readyState == 'complete') {
                complete.apply(this, arguments);
            }
        }
        head.appendChild(scriptTag);
    }
}

loadScriptsInParallel([
    "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js",
    "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"
], function() {
    // jQuery example code
    $("#test").html("scripts are loaded");
});