Skip to content

Instantly share code, notes, and snippets.

@stubotnik
Created July 19, 2012 07:41
Show Gist options
  • Save stubotnik/3141401 to your computer and use it in GitHub Desktop.
Save stubotnik/3141401 to your computer and use it in GitHub Desktop.
Dynamic resource loading with LAB.js
DynResourceLoader = Class.create({
initialize: function () {
document.observe("custom:pageAddedToDOM", this.load.bind(this));
},
load: function (e) {
var page = e.memo;
if (page.hasAttribute("data-required-js")) {
page.getAttribute("data-required-js").split(/,[ ]*/).each(function (r) {
$LAB.queueScript(r);
$LAB.queueWait(); //wait forces ordered execution (downloads can still be parallel)
});
$LAB.runQueue();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment