bundle-preload — Claude Code rule: what it does, how to install
bundle-preload directs the agent to preload heavy JavaScript chunks on user intent like hover or focus. This cuts perceived interface latency.
MIT ★ 7,191 updated 2026-10-24
.claude/rules/bundle-preload.mdWhat bundle-preload does
This rule instructs Claude Code to trigger dynamic module imports before a user action completes. Instead of waiting for a click event, the code runs dynamic imports on onMouseEnter or onFocus, or when a feature flag toggles inside a provider.
Every suggested preload snippet checks typeof window !== 'undefined'. Skipping this guard causes preloaded modules to bundle into SSR outputs, increasing server bundle size and slowing build times.
What it helps with
- preload heavy client modules ahead of user clicks
- trigger dynamic imports on button hover or focus
- fetch editor bundles when a feature flag turns on
- prevent client chunks from bundling into SSR builds
Example prompts for the agent
- Add editor bundle preloading to this button on hover and focus
- Set up intent-based preloading for the heavy modal component
- Preload the editor chunk inside FlagsProvider when the flag is enabled
How to install bundle-preload
Manually: put the files in place
.claude/rules/bundle-preload.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-preload.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/bundle-preload.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/bundle-preload.mdManually: put the files in place
.clinerules/bundle-preload.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about bundle-preload
How to install bundle-preload in Claude Code?
Save the rule file to .claude/rules/bundle-preload.md.
What does the bundle-preload rule do?
It guides Claude Code to preload heavy bundles on focus, hover, or feature flag updates via dynamic imports.
Why is typeof window checked before preloading?
The typeof window !== 'undefined' check keeps preloaded modules out of server-side bundles during SSR, optimizing server bundle size.
Source text
bundle-preload.md · MIT
---
title: Preload Based on User Intent
impact: MEDIUM
impactDescription: reduces perceived latency
tags: bundle, preload, user-intent, hover
---
## Preload Based on User Intent
Preload heavy bundles before they're needed to reduce perceived latency.
**Example (preload on hover/focus):**
```tsx
function EditorButton({ onClick }: { onClick: () => void }) {
const preload = () => {
if (typeof window !== 'undefined') {
void import('./monaco-editor')
}
}
return (
<button
onMouseEnter={preload}
onFocus={preload}
onClick={onClick}
>
Open Editor
</button>
)
}
```
**Example (preload when feature flag is enabled):**
```tsx
function FlagsProvider({ children, flags }: Props) {
useEffect(() => {
if (flags.editorEnabled && typeof window !== 'undefined') {
void import('./monaco-editor').then(mod => mod.init())
}
}, [flags.editorEnabled])
return <FlagsContext.Provider value={flags}>
{children}
</FlagsContext.Provider>
}
```
The `typeof window !== 'undefined'` check prevents bundling preloaded modules for SSR, optimizing server bundle size and build speed.
© tech-leads-club · MIT · tech-leads-club/agent-skills