Reputation: 3605
Client side, can we import a JavaScript module in the <script></script>
tag of a HTML page without loading an external script?
<html>
<head>
...
</head>
<body>
...
<script>
document.getElementById('btn').onclick = () => {
// Import a JS module here
}
</script>
</body>
</html>
Upvotes: 1
Views: 46
Reputation: 1216
Do not use import * as label from "file.js"
. Use the following code:
<html>
<head>
...
</head>
<body>
...
<script>
document.getElementById('btn').onclick = () => {
// Import a JS module here
import("file.js").then(obj => {
// Do something with obj
})
}
</script>
</body>
</html>
Upvotes: 1