Skip to content

Instantly share code, notes, and snippets.

@livelikeabel
Last active July 28, 2019 13:50
Show Gist options
  • Select an option

  • Save livelikeabel/969d377e709fbda5c3565df1b2aaff86 to your computer and use it in GitHub Desktop.

Select an option

Save livelikeabel/969d377e709fbda5c3565df1b2aaff86 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<button id="btn" onclick="myLoader()">submit</button>
<script>
function scriptLoader(src) {
const el = document.createElement('script');
el.type = 'text/javascript';
el.src = src;
document.body.appendChild(el);
return new Promise((resolve, reject) => {
el.onload = () => resolve('Successful script loading');
el.onerror = () => reject(new Error(`Not loaded script '${src}'`));
});
};
scriptLoader("https://unpkg.com/react@16/umd/react.development.js")
.then(res => console.log('succes!', res))
.catch(err => console.log(err))
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment