Skip to main content
rule CX Codex

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

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/bundle-preload.md
Open on GitHub

What 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.md

The paths frontmatter field limits the files

Step 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

Similar IDE rules

All IDE rules for Frontend and UI →
preload patterns.dev Guides the AI agent on preloading critical web assets. Useful when hero images, web fonts, or key bundles are discovered late in the loading waterfall. CX Codex +1 1,700installs next-bundle-optimizer vercel next-bundle-optimizer audits the initial browser work of a Next.js app: slow route startup, oversized client bundles, duplicate dependencies, features that could wait for interaction. CX Codex +1 4,800installs rendering-resource-hints fcakyon The rendering-resource-hints rule tells the agent when to call React DOM's resource-hint functions inside React components. It targets server components, letting the browser start fetching assets before the client even has the HTML. CX Codex +1 ★ 1,216repo stars agentic-bundle-aas-accessibility-inclusive-ux sickn33 and contributors agentic-bundle-aas-accessibility-inclusive-ux is a Claude Code plugin for an editorial skill bundle about accessibility and inclusive UX. Its subject is relevant to work that addresses either topic. CX Codex ★ 50,109repo stars agentic-bundle-aas-mobile-app-builder sickn33 and contributors agentic-bundle-aas-mobile-app-builder — a curated skill bundle for mobile app development in Claude Code. Includes ready-to-use tools and templates to accelerate the creation of functional mobile solutions. CX Codex ★ 50,109repo stars bundle-analyzable-paths fcakyon The bundle-analyzable-paths rule recommends making import and file paths statically analyzable. That keeps bundlers from treating a broad set of files as reachable. CX Codex +1 ★ 1,216repo stars

From the same set130

The whole set →
advanced-use-latest advanced-use-latest — a Claude rule file on reaching fresh callback values inside a React effect and keeping the dependency array down to state. CX Codex +1 ★ 7,191repo stars async-api-routes async-api-routes prevents sequential waterfall requests in API routes and Server Actions. It instructs the assistant to launch independent promises immediately rather than chaining awaits. CX Codex +1 ★ 7,191repo stars js-early-exit The js-early-exit rule recommends returning as soon as a function’s result is clear. It fits checks where continuing after the first error serves no purpose. CX Codex +1 ★ 7,191repo stars rerender-memo rerender-memo — a rule that guides your agent to extract expensive computations into memoized components, enabling early returns without triggering child logic. Speeds up React re-render paths. CX Codex +1 ★ 7,191repo stars client-swr-dedup The client-swr-dedup rule recommends SWR to share requests between component instances and reuse cached data. It fits React projects that fetch data on the client. CX Codex +1 ★ 7,191repo stars rerender-memo-with-default-value rerender-memo-with-default-value — a rule that prevents memoization from breaking when React components have default values (functions, objects, arrays) in parameters. It instructs you to extract these defaults into module-level constants. CX Codex +1 ★ 7,191repo stars rendering-animate-svg-wrapper rendering-animate-svg-wrapper enforces wrapping svg elements in an outer div container for CSS animations. Enables GPU hardware acceleration across browsers. CX Codex +1 ★ 7,191repo stars rerender-derived-state-no-effect The rerender-derived-state-no-effect rule keeps derived values out of React state and avoids effects that mirror props. Use it when reviewing components for extra renders and state drift. CX Codex +1 ★ 7,191repo stars

Project sponsors

Companies that keep this analytics open