Skip to content

Instantly share code, notes, and snippets.

@benjaco
Created April 26, 2017 01:11
Show Gist options
  • Save benjaco/4a2e7616176466076b8a5a067d3092e8 to your computer and use it in GitHub Desktop.
Save benjaco/4a2e7616176466076b8a5a067d3092e8 to your computer and use it in GitHub Desktop.
lazyload js
function loadJs(url){
return new Promise((resolve, reject)=>{
var script = document.createElement('script');
script.src = url;
script.onload = resolve
script.onerror = reject
document.head.appendChild(script);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment