-
Notifications
You must be signed in to change notification settings - Fork 32
/
dynamic_import.html
37 lines (34 loc) · 981 Bytes
/
dynamic_import.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Module Import Example</title>
<style>
/* Add your CSS styles here */
</style>
</head>
<body>
<h1>Dynamic Module Import Example</h1>
<form id="cakeForm">
<button type="submit">Create Cakes</button>
</form>
<script>
document.addEventListener("DOMContentLoaded", () => {
const form = document.getElementById("cakeForm");
form.addEventListener("submit", e => {
e.preventDefault();
import("./modules/cakeFactory.mjs")
.then((module) => {
// Do something with the module.
module.cakeFactory.oven.makeCupcake("sprinkles");
module.cakeFactory.oven.makeMuffin("large");
})
.catch((error) => {
console.error("Error importing module:", error);
});
});
});
</script>
</body>
</html>