function import

Voici une importation conditionnel à un click grâce à la fonction : 
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="module" defer src="./script.js"></script>
</head>
<body>
click and see the console
</body>
</html>
view raw index.html hosted with ❤ by GitHub
export default function printModule(){
console.log("from module")
}
export function cl(){
console.log("top")
}
view raw module.js hosted with ❤ by GitHub
document.addEventListener("click", async () => {
const {default: printModule, cl } = await import("./module.js");
printModule();
cl();
console.log("from script")
});
view raw script.js hosted with ❤ by GitHub
import("./module.js");