Skip to main content
rule CX Codex

bundle-conditional — Claude Code rule for conditional loading

The bundle-conditional rule recommends loading large modules only when their feature is activated. It applies to lazy-loaded data and browser-only code in SSR builds.

MIT ★ 7,191 updated 2026-10-24

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

What bundle-conditional does

bundle-conditional recommends loading large data or modules only when a feature needs them. Its React example imports animation frames after the player is enabled, shows a placeholder while they load, and disables the feature if the import fails.

The typeof window !== 'undefined' check keeps a browser-only module out of the server bundle during SSR, reducing bundle size and build time. Without that check, the server build could include code intended for the browser. In Claude Code, the rule file goes at .claude/rules/bundle-conditional.md.

What it helps with

  • defer animation-frame loading until the player is enabled
  • keep browser-only modules out of an SSR server bundle
  • show a placeholder while module data loads
  • turn off a feature when its import fails

Example prompts for the agent

  • Apply bundle-conditional to the animation player’s frame loading.
  • Check whether this module can load only after its feature is enabled.
  • Add an SSR check so browser-only code stays out of the server bundle.

How to install bundle-conditional

Manually: put the files in place

.claude/rules/bundle-conditional.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-conditional

How do I install bundle-conditional in Claude Code?

Add the rule file at .claude/rules/bundle-conditional.md.

What does bundle-conditional do?

It recommends loading large modules or data when the related feature is activated. The example uses import() to fetch animation frames after the player is enabled.

Why does the rule check typeof window !== 'undefined'?

The check prevents a browser-only module from entering the server bundle during SSR. That reduces server bundle size and build time.

Source text

bundle-conditional.md · MIT
---
title: Conditional Module Loading
impact: HIGH
impactDescription: loads large data only when needed
tags: bundle, conditional-loading, lazy-loading
---

## Conditional Module Loading

Load large data or modules only when a feature is activated.

**Example (lazy-load animation frames):**

```tsx
function AnimationPlayer({ enabled, setEnabled }: { enabled: boolean; setEnabled: React.Dispatch<React.SetStateAction<boolean>> }) {
  const [frames, setFrames] = useState<Frame[] | null>(null)

  useEffect(() => {
    if (enabled && !frames && typeof window !== 'undefined') {
      import('./animation-frames.js')
        .then(mod => setFrames(mod.frames))
        .catch(() => setEnabled(false))
    }
  }, [enabled, frames, setEnabled])

  if (!frames) return <Skeleton />
  return <Canvas frames={frames} />
}
```

The `typeof window !== 'undefined'` check prevents bundling this module 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 →
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 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 import-on-visibility patterns.dev import-on-visibility — a skill that teaches the agent to defer components and images until the user scrolls them into view. Useful when your first paint is dragging. CX Codex +1 1,700installs import-on-interaction patterns.dev import-on-interaction — a skill that teaches the agent to defer heavy components and widgets until a click, hover or form input actually needs them. CX Codex +1 1,700installs 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 →
best-practices best-practices is a Claude Code skill for checking web code security, browser compatibility, and code quality. It runs on requests for a security review or code modernization. CX Codex +1 ★ 7,191repo stars js-index-maps The js-index-maps rule replaces repeated .find() calls on one key with a Map index. Use it when array lookups happen many times. CX Codex +1 ★ 7,191repo stars rendering-hydration-suppress-warning rendering-hydration-suppress-warning silences hydration warnings where the two renders are meant to differ: timestamps, per-render IDs, dates formatted for the visitor's locale. CX Codex +1 ★ 7,191repo stars bundle-defer-third-party bundle-defer-third-party prevents third-party trackers from inflating the initial bundle. It instructs the assistant to load analytics and monitoring after hydration. CX Codex +1 ★ 7,191repo stars react19-no-forwardref react19-no-forwardref is a Claude Code rule covering React 19 ref and context changes: pass ref as a prop and use use() instead of useContext(). It supports React 19 migrations. CX Codex +1 ★ 7,191repo stars advanced-init-once advanced-init-once prevents running app-wide startup logic inside component useEffect([]) hooks and suggests module-level guards or top-level initialization instead. CX Codex +1 ★ 7,191repo stars rerender-defer-reads The rerender-defer-reads rule keeps callback-only reads of dynamic state out of component subscriptions. Use it when searchParams or localStorage is needed only after an action. CX Codex +1 ★ 7,191repo stars rendering-conditional-render The rendering-conditional-render rule prevents accidental rendering of zeros and NaN in JSX. It enforces explicit ternary operators instead of && checks, so falsy values stay out of the DOM. CX Codex +1 ★ 7,191repo stars

Project sponsors

Companies that keep this analytics open