Dynamic loading of Javascript dependency graph I have JavaScript module for loading dynamically script files by dependency graph:

var module = {};

module.loadScript = function (url, callback) {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = url;
    script.async = true;
    script.charset = 'utf-8';
    document.body.appendChild(script);
    console.time(script.src + ' Load');

    module.addEvent(script, 'load', function () {
        console.timeEnd(this.src + ' Load');
        document.body.removeChild(this);

        if (typeof callback === "function") {
            callback();
        }
    });
};

module.loadJsTree = function (tree, callback) {
    _loadJsTreeInternal(tree, callback, 0, 0);
};

function _loadJsTreeInternal (tree, callback, _totalCount, _loadedCount) {
    tree = tree || {};

    var branches = Object.keys(tree);
    _totalCount += branches.length;

    branches.forEach(function (branch, index) {
        console.log("Start load ", branch, tree[branch]);

        module.loadScript(branch, function () {
            _loadedCount++;

            if (tree[branch] !== null &amp;&amp; typeof tree[branch] === 'object') {
                _loadJsTreeInternal(tree[branch], callback, _totalCount, _loadedCount);
            }
            else if (_loadedCount == _totalCount) {
                if (typeof callback === "function") {
                    callback();
                }
            }
        });
    });
}

//RUN SCRIPT

var scripts = {
    '/script1.js': null,
    '/script2.js': {
        '/script2.plugin1.js': {
            '/script2.plugin1.plugin1.js': null
        },
        '/script2.plugin2.js': null
    }
};

module.loadJsTree(scripts, function () { alert("ALL SCRIPTS READY!") });


Do you see any other improvements / issues?
I have JavaScript module for loading dynamically script files by dependency graph:


But... why? There are libraries out there that already do this. Take for instance, RequireJS. Most libraries out there ship as UMD modules (defined as CommonJS, AMD, and global), you can easily drop them into RequireJS-like or Browserify-like workflows. 

Also, if you already know the order at which the modules come in (because of your deps graph), why not take a step further and just use ES modules together with a bundler like Rollup? Together with Uglify, you can strip away unnecessary bloat. Aside from the tooling, ES modules explicitly define their dependencies. You don't need an external deps map.

Async loading of modules all at once only prevent render-blocking and make your site look fast. It does not speed up loading of the site. What makes sites faster is smaller or lesser dependencies, or async loading plus loading only what's needed at the moment.

Consider using the tools existing in the ecosystem instead of building your own.