JavaScript·Intermediate·Coding·1 min read
How does dynamic import help performance?
Short interview answer
import() returns a promise and creates a runtime loading boundary that bundlers can turn into a separate chunk. Use it around optional or route-level functionality; excessive tiny chunks add network and execution overhead.
Example
button.addEventListener('click', async () => { const { openEditor } = await import('./editor.js'); // separate chunk openEditor();});Key takeaway
Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.