Dev.Lib
arrow_backBack to Blogs
LEVEL_011.6June 27, 20261 min read

Dynamic import chunking

Frontend Fundamentals

`import()` creates async chunks named by bundler (webpack magic comments, Vite rollup output).

Summary

import() creates async chunks named by bundler (webpack magic comments, Vite rollup output). Shared dependencies hoist to common chunks — changing one dynamic import can reshuffle hashes. Use webpackPrefetch/modulepreload for likely-next routes. Verify chunk size in analyzer, not just count.

Code example

async function loadChart() {
  const { renderChart } = await import(
    /* webpackPrefetch: true */ './chart-module.js'
  );
  renderChart('#canvas');
}

Key points

  • import() creates async chunks named by bundler (webpack magic comments, Vite rollup output).
  • Shared dependencies hoist to common chunks — changing one dynamic import can reshuffle hashes.
  • Use webpackPrefetch/modulepreload for likely-next routes.
  • Verify chunk size in analyzer, not just count.

Further reading

Related concepts