Use import() as a function for dynamic imports. It returns a promise that resolves to the module.
button.onclick = async () => {
const { heavy } = await import("./heavy.js");
heavy();
};
Dynamic imports enable code splitting. Load modules only when needed.