Created
May 20, 2015 15:24
-
-
Save stefan-vatov/b0a7b3a8ebbf60c4b3b9 to your computer and use it in GitHub Desktop.
Dynamically load JS & CSS
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 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