# bundle-dynamic-imports

bundle-dynamic-imports guides Claude Code to lazy-load heavy components using next/dynamic with SSR disabled. Keeps your initial client bundle lean to protect TTI and LCP metrics.

- rule · `type=rule` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline · ★ 1064 repo stars
- Author: jarrodwatts
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/jarrodwatts/claude-code-config/tree/HEAD/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md
- Updated: 2026-01-21
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/rules/bundle-dynamic-imports

## What it does

This rule instructs the agent to avoid static imports for bulky components not needed on initial render. Claude Code switches to `next/dynamic` so the app splits those heavy modules into separate chunks. This keeps main bundles compact.

The guidance demonstrates on-demand loading via `import()` alongside `{ ssr: false }`. Client-only tools like code editors stay out of the server bundle. The requirement directly targets TTI and LCP degradation. Because it relies on Next.js conventions, using it in other bundlers will fail.

## Install

### Claude Code (native platform)

**Manually: put the files in place**
- File: `.claude/rules/bundle-dynamic-imports.md` — The paths frontmatter field limits the files

### Codex

**AGENTS.md**
- Codex reads AGENTS.md: paste the rule text there

### Cursor

**Manually: put the files in place**
- File: `.cursor/rules/bundle-dynamic-imports.mdc` — Frontmatter: description, globs, alwaysApply

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/instructions/bundle-dynamic-imports.instructions.md` — The applyTo field sets which files it applies to

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/rules/bundle-dynamic-imports.md`

### Cline

**Manually: put the files in place**
- File: `.clinerules/bundle-dynamic-imports.md`

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/jarrodwatts/claude-code-config/tree/HEAD/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md

## When to use it
- split oversized components into separate chunks using `next/dynamic`
- prevent editor or chart code from bloating the initial JavaScript payload
- protect TTI and LCP metrics during frontend refactoring
- turn off server-side rendering for browser-only UI widgets

## Example prompts
- Refactor `monaco-panel.tsx` to load the code editor dynamically
- Add our analytics chart component to the dashboard without bundling it upfront
- Lazy-load the heavy markdown preview using next/dynamic with ssr turned off

## Similar
- [bundle-barrel-imports](https://affpapa.org/en/nevibecode/rules/bundle-barrel-imports.md) — rule · ★ 7191 repo stars
- [vite-bundle-optimization](https://affpapa.org/en/nevibecode/skills/vite-bundle-optimization.md) — skill · 692 installs
- [react-performance-optimizer](https://affpapa.org/en/nevibecode/agents/react-performance-optimizer.md) — subagent · 2081 installs
- [next-bundle-optimizer](https://affpapa.org/en/nevibecode/skills/next-bundle-optimizer.md) — skill · 4800 installs
- [plugin-bundle-size](https://affpapa.org/en/nevibecode/skills/plugin-bundle-size.md) — skill · 4600 installs
- [react-vite-best-practices](https://affpapa.org/en/nevibecode/skills/react-vite-best-practices.md) — skill · 3000 installs

From the same set: [jarrodwatts/claude-code-config](https://affpapa.org/en/nevibecode/by/jarrodwatts/claude-code-config.md) — 20 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
