Dynamic Imports
MediumIn plain terms
import() returns a Promise. Load modules on demand (code splitting). Use when path or need is dynamic. Async/await with import().
What you need to know
- •import() returns Promise
- •Code splitting
- •Dynamic paths
Try it yourself
Copy the code below and run it in your browser console or a code editor:
const mod = await import('./utils.js'); mod.fn(); if (condition) { const { fn } = await import('./heavy.js'); }Learn more
Dive deeper with these trusted resources: