Skip to content

Instantly share code, notes, and snippets.

@SmugZombie
Last active August 23, 2016 17:07
Show Gist options
  • Select an option

  • Save SmugZombie/7785125a86ef4e8488414cd0991dd28a to your computer and use it in GitHub Desktop.

Select an option

Save SmugZombie/7785125a86ef4e8488414cd0991dd28a to your computer and use it in GitHub Desktop.
function include(type, source){
//Includes external resources via injection
var head = document.getElementsByTagName('head')[0];
switch(type){
case 'js': {
resource = document.createElement('script');
resource.type = 'text/javascript';
resource.src = source;
break;
}
case 'css': {
resource = document.createElement('link');
resource.rel = 'stylesheet';
resource.type = 'text/css';
resource.href = source;
break;
}
}
console.log('Included ' + type + ': ' + source);
head.appendChild(resource);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment