Created
September 8, 2010 04:38
-
-
Save charlesjolley/569633 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var queue = []; | |
var scripts ={}; | |
function loadIt(scriptname) { | |
queue.push(scriptname); | |
if (!scripts[scriptname]) { | |
var el = document.createElement('script'); | |
el.src = scriptname; | |
document.head.appendElement(el); | |
} else pump(); | |
} | |
function fullfill(scriptname, script) { | |
scripts[scriptname] = script; | |
pump(); | |
} | |
function pump() { | |
if (queue.length === 0) return; // nothing to do | |
var name = queue[0]; | |
if (scripts[name]) { | |
queue.shift(); // remove item | |
eval(scripts[name]); | |
setTimeout(pump, 1); // try to pump again. take a break to avoid slow scripts | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment