Dynamic import is a JavaScript language feature (Stage 4). Bundlers create separate "chunks" for dynamically imported modules, loaded via <script> tags at runtime.
Chunk naming strategy:
Route-based: one chunk per top-level route
Feature-based: one chunk per large feature (chart library, editor, admin panel)
Vendor splitting: separate chunks for node_modules (better long-term caching)
Preloading:<link rel="preload"> or import() on hover/route-change triggers network fetch before the user needs it, hiding latency. Framework routers (Next.js, React Router) do this automatically for adjacent routes.
Measurement: Analyze bundle with vite build --report or webpack-bundle-analyzer before and after splitting.
Read the instructions and examples in this document.
Apply the patterns to your implementation, adapting to your specific context.
Verify your implementation against the details and edge cases listed above.
Harness Integration
Type: knowledge — this skill is a reference document, not a procedural workflow.
No tools or state — consumed as context by other skills and agents.
Success Criteria
The patterns described in this document are applied correctly in the implementation.
Edge cases and anti-patterns listed in this document are avoided.
1---2name: react-dynamic-import3description: React Dynamic Import4---5# React Dynamic Import67> Load modules on demand to reduce initial bundle size and improve startup performance89## When to Use1011- A component is only needed after user interaction (modal, drawer, tab panel)12- A route's components should not be in the initial bundle (route-based splitting)13- A large library is only used in a specific feature14- Below-fold content that users may never scroll to1516## Instructions17181. Use `React.lazy` with a dynamic `import()` for component splitting:19 ```typescript20 const Modal = React.lazy(() => import('./Modal'));21 ```222. Always wrap lazy components in `<Suspense>` with a fallback.233. For non-component modules, use `import()` directly:24 ```typescript25 const { heavyComputation } = await import('./heavy-utils');26 ```274. Add webpack/vite magic comments for named chunks:28 ```typescript29 const Chart = React.lazy(() => import(/* webpackChunkName: "chart" */ './Chart'));30 ```315. Preload on hover for likely interactions:32 ```typescript33 const preload = () => import('./Modal');34 <button onMouseEnter={preload} onClick={openModal}>Open</button>35 ```3637## Details3839Dynamic import is a JavaScript language feature (Stage 4). Bundlers create separate "chunks" for dynamically imported modules, loaded via `<script>` tags at runtime.4041**Chunk naming strategy:**4243- Route-based: one chunk per top-level route44- Feature-based: one chunk per large feature (chart library, editor, admin panel)45- Vendor splitting: separate chunks for node_modules (better long-term caching)4647**Preloading:** `<link rel="preload">` or `import()` on hover/route-change triggers network fetch before the user needs it, hiding latency. Framework routers (Next.js, React Router) do this automatically for adjacent routes.4849**Measurement:** Analyze bundle with `vite build --report` or `webpack-bundle-analyzer` before and after splitting.5051## Source5253https://patterns.dev/react/dynamic-import5455## Process56571. Read the instructions and examples in this document.582. Apply the patterns to your implementation, adapting to your specific context.593. Verify your implementation against the details and edge cases listed above.6061## Harness Integration6263- **Type:** knowledge — this skill is a reference document, not a procedural workflow.64- **No tools or state** — consumed as context by other skills and agents.6566## Success Criteria6768- The patterns described in this document are applied correctly in the implementation.69- Edge cases and anti-patterns listed in this document are avoided.
Run npx skillmds@latest add intense-visions/react-dynamic-import in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
React Dynamic Import It is listed under Web & Frontend on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Intense-Visions (@intense-visions) published this skill. Their other Agent Skills are listed on their SkillMD profile.