@shinin/load-script
is a simple async script loader for modern browsers.
import loadScript from '@shinin/load-script'
export default async function loadSDK() {
await loadScript('http://foo.bar/sdk.js')
// Now, you can do what you want after SDK.js has loaded...
}
npm install @shinin/load-script --save
Also you can use @shinin/load-script
as a <script>
tag from a CDN.
<!-- Use promise-polyfill only if you want to support old browsers. -->
<!-- <script src="https://unpkg.com/promise-polyfill"></script> -->
<script src="https://unpkg.com/@shinin/load-script/dist/load-script.min.js"></script>
- Chrome
- Firefox
- Safari 7.1+
- Safari 5.1+ (with promises-polyfill)
- IE 8+ (with promises-polyfill)