Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Created January 22, 2020 21:55
Show Gist options
  • Save kentcdodds/48c069462a9ab4223eb93b5e19acee31 to your computer and use it in GitHub Desktop.
Save kentcdodds/48c069462a9ab4223eb93b5e19acee31 to your computer and use it in GitHub Desktop.
function appendDiv(message) {
const div = document.createElement('div')
div.textContent = message
document.body.appendChild(div)
}
export {appendDiv}
import {appendDiv} from './append-div.js'
function go() {
appendDiv('Hello from async script')
}
export {go}
<script type="module">
import {appendDiv} from './append-div.js'
appendDiv('Hello from inline script')
</script>
<script type="module" src="./script-src.js"></script>
import {appendDiv} from './append-div.js'
appendDiv('Hello from external script')
import('./async-script.js').then(
moduleExports => {
moduleExports.go()
},
error => {
console.error('there was an error loading the script')
throw error
},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment