Dynamic Import
JS · Modulessyntax
const module = await import("./module.js");example
async function loadEditor() {
const { EditorView } = await import("./editor.js");
return new EditorView(document.getElementById("editor"));
}
// Conditional loading
if (needsCharting) {
const { renderChart } = await import("./charts.js");
renderChart(data);
}Note Returns a promise that resolves to the module namespace. Ideal for code-splitting, lazy loading, and conditional imports. Works at runtime, not just at the top of a file.