Skip to content

Instantly share code, notes, and snippets.

@Thecarisma
Last active December 31, 2019 21:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thecarisma/f1fac7988b19981980752cae9f66352a to your computer and use it in GitHub Desktop.
Save Thecarisma/f1fac7988b19981980752cae9f66352a to your computer and use it in GitHub Desktop.
Load a remote javascript file in the browser synchronously. Wait till loading complete with callback.
//Example: log 'Hello World' after language-colors.css load completed
/**
loadScript("https://quickutils.github.io/language-colors/language-colors.css", function() {
console.log('Hello World');
});
**/
function loadScript(url, callback) {
var head = document.body;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
script.onreadystatechange = callback;
script.onload = callback;
head.appendChild(script);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment