Insert css or javascript dynamically
That's a super simple function for adding new css or javascript files in the current document. I didn't test it in all the browsers, because I'm using it in the chrome extension and I need only Chrome supported.
var injectFiles = function(files, callback) { var filesLoaded = 0; var parent = document.querySelector("body") || document.querySelector("head"); var onFileLoaded = function() { if(++filesLoaded == files.length) { callback(); } } for(var i=0; iUsage:
injectFiles(["css/styles.css", "js/vendor/jquery.js"], function() { // do some other stuff here });