Skip to content

Instantly share code, notes, and snippets.

@kyletaylored
Last active February 14, 2019 00:53
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 kyletaylored/e587993a562555becc24986852e7dba5 to your computer and use it in GitHub Desktop.
Save kyletaylored/e587993a562555becc24986852e7dba5 to your computer and use it in GitHub Desktop.
Load scripts with JS
// Load JS function
var loadJS = function(url, callback){
var scriptTag = document.createElement('script');
scriptTag.src = url;
scriptTag.onload = callback;
scriptTag.onreadystatechange = callback;
document.body.appendChild(scriptTag);
};
// Load CSS function
var loadCSS = function(url) {
var styleTag = document.createElement('link');
styleTag.href = url;
styleTag.rel = "stylesheet";
styleTag.type= "text/css";
document.head.appendChild(styleTag);
};
jQuery(document).ready(function() {
// var protocol = location.protocol; (optional)
loadJS('URL', <callback>);
loadCSS('URL');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment