Skip to content

Instantly share code, notes, and snippets.

@seayxu
Created April 19, 2016 16:18
Show Gist options
  • Save seayxu/67877df8fdc80425e0396557567edab3 to your computer and use it in GitHub Desktop.
Save seayxu/67877df8fdc80425e0396557567edab3 to your computer and use it in GitHub Desktop.
dynamic load css and javascript file
//dynamic load css file
function loadcss(path){
if(!path || path.length === 0){
throw new Error('argument "path" is required !');
}
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.href = path;
link.rel = 'stylesheet';
link.type = 'text/css';
head.appendChild(link);
}
//dynamic load javascript file
function loadjs(path){
if(!path || path.length === 0){
throw new Error('argument "path" is required !');
}
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.src = path;
script.type = 'text/javascript';
head.appendChild(script);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment