Skip to content

Instantly share code, notes, and snippets.

@davidcalhoun
Created January 4, 2020 18:51
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 davidcalhoun/cabe908b3e5c1ceddb16a08e7fcc69bb to your computer and use it in GitHub Desktop.
Save davidcalhoun/cabe908b3e5c1ceddb16a08e7fcc69bb to your computer and use it in GitHub Desktop.
simple script loader.js
function initSyntaxHighlighting() {
// code
}
function loadScripts() {
const scripts = [
{
src: 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js',
callback: initSyntaxHighlighting
}
];
scripts.forEach(function(script) {
const elt = document.createElement('script');
elt.setAttribute('async', '');
elt.setAttribute('defer', '');
elt.setAttribute('src', script.src);
elt.addEventListener('load', script.callback, true);
document.head.appendChild(elt);
});
}
loadScripts()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment