Skip to content

Instantly share code, notes, and snippets.

@stefan-vatov
Created May 20, 2015 15:24
Show Gist options
  • Save stefan-vatov/b0a7b3a8ebbf60c4b3b9 to your computer and use it in GitHub Desktop.
Save stefan-vatov/b0a7b3a8ebbf60c4b3b9 to your computer and use it in GitHub Desktop.
Dynamically load JS & CSS
var loadCSS = function (href) {
var cssLink = $("<link rel='stylesheet' type='text/css' href='" + href + "'>");
$("head").append(cssLink);
};
// Could load the JS at the end of the body, depends on the case
var loadJS = function (src) {
var jsLink = $("<script type='text/javascript' src='" + src + "'>");
$("head").append(jsLink);
};
// Using Underscore to loop through a collection of the files and load each
_.each(cssFiles, function (cssLink) {
loadCSS(cssLink);
});
_.each(jsFiles, function (cssLink) {
loadJS(cssLink);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment