bundle-dynamic-imports — Claude Code rule: usage and setup
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.
no license ★ 1,064 updated 2026-01-21
.claude/rules/bundle-dynamic-imports.mdWhat bundle-dynamic-imports 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.
What it helps with
- 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 for the agent
- Refactor
monaco-panel.tsxto 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
How to install bundle-dynamic-imports
Manually: put the files in place
.claude/rules/bundle-dynamic-imports.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/bundle-dynamic-imports.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/bundle-dynamic-imports.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/bundle-dynamic-imports.mdManually: put the files in place
.clinerules/bundle-dynamic-imports.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about bundle-dynamic-imports
How to install bundle-dynamic-imports in Claude Code?
Save the instruction file to .claude/rules/bundle-dynamic-imports.md inside your repository. Claude Code will read it automatically during coding sessions.
What does bundle-dynamic-imports do?
It forces the model to use next/dynamic instead of standard imports for large components. This delays loading until the component is actually needed in the browser.
Why does the rule specify ssr: false?
It prevents Next.js from rendering the component during server prerendering. This avoids hydration errors for modules that depend on browser APIs.