Last active
October 29, 2020 14:18
-
-
Save sulram/b154a92bd2085df6df26c04bb2fb7f6a to your computer and use it in GitHub Desktop.
load/inject scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const injectScript = (id,url,callback) => { | |
const existingScript = document.getElementById(id) | |
if (!existingScript) { | |
const script = document.createElement('script') | |
script.src = url | |
script.id = id | |
document.body.appendChild(script) | |
script.onload = () => { | |
if (callback) callback() | |
} | |
} | |
if (existingScript && callback) callback() | |
} | |
injectScript('react','https://unpkg.com/[email protected]/umd/react.production.min.js') | |
injectScript('react-dom','https://unpkg.com/[email protected]/umd/react-dom.production.min.js') | |
injectScript('emotion-core','https://unpkg.com/@emotion/[email protected]/dist/core.umd.min.js') | |
injectScript('emotion-styled','https://www.unpkg.com/@emotion/[email protected]/dist/styled-base.umd.min.js') | |
injectScript('main-script','app.js') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment