Skip to content

Instantly share code, notes, and snippets.

@mattbontrager
Created June 15, 2018 22:58
Show Gist options
  • Save mattbontrager/8fadc0cba57dacc6d3dea2405e29dbb3 to your computer and use it in GitHub Desktop.
Save mattbontrager/8fadc0cba57dacc6d3dea2405e29dbb3 to your computer and use it in GitHub Desktop.
Asynchronously load other JavaScript files.
const loadScript = src => {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.async = true;
script.src = src;
script.onload = resolve;
script.onerror = reject;
document.body.appendChild(script);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment