Skip to content

Instantly share code, notes, and snippets.

@milosdjakonovic
Last active November 8, 2016 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milosdjakonovic/f0617e85fd78f5db84a09a2a634a3b41 to your computer and use it in GitHub Desktop.
Save milosdjakonovic/f0617e85fd78f5db84a09a2a634a3b41 to your computer and use it in GitHub Desktop.
Dynamic css loader
;(function(w,d){
var head = d.head || d.getElementsByTagName('head')[0],
raf = w.requestAnimationFrame ||
w.mozRequestAnimationFrame ||
w.webkitRequestAnimationFrame ||
w.msRequestAnimationFrame ||
function(callback) {
return setTimeout(callback, 16)
},
createAndAddLink = function(href){
var link = d.createElement('link');
link.rel="stylesheet";
link.media="all";
link.href = href;
raf(function(){
head.appendChild(link);
});
}
w.loadCss = function(){
var args = arguments;
if(typeof args === 'string'){
createAndAddLink(args);
return;
}
for(var i=0;i<args.length;i++){
createAndAddLink(args[i]);
}
};
})(window,document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment