Skip to content

Instantly share code, notes, and snippets.

@allex
Forked from esamattis/loadscript.js
Created February 28, 2019 07:06
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 allex/423599a745a2af1e585a8f548002478c to your computer and use it in GitHub Desktop.
Save allex/423599a745a2af1e585a8f548002478c to your computer and use it in GitHub Desktop.
/**
* Simple node.js style script loader for modern browsers
**/
function loadScript(src, cb) {
var script = document.createElement('script');
script.async = true;
script.src = src;
script.onerror = function() {
cb(new Error("Failed to load" + src));
};
script.onload = function() {
cb();
};
document.getElementsByTagName("head")[0].appendChild(script);
}
module.exports = loadScript;
@allex
Copy link
Author

allex commented Feb 28, 2019

// one line loadScript for console shortcut execute.
function loadScript(n,e){var o=document,t=o.createElement("script");e=e||function(){},t.async=!0,t.src=n,t.onerror=function(){e(new Error("Failed to load"+n))},t.onload=function(){e()},o.getElementsByTagName("head")[0].appendChild(t)}
loadScript('//s1.hitv.com/libs/??jquery/1.12.4/jquery.min.js');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment