Created
July 19, 2012 07:41
-
-
Save stubotnik/3141401 to your computer and use it in GitHub Desktop.
Dynamic resource loading with LAB.js
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
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