code-splitting

Implement React 19 code splitting with lazy() and Suspense.

Updated Nov 21, 2025
One-click install
npx skills add https://github.com/djankies/claude-configs --skill code-splitting
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: code-splitting
Source: https://github.com/djankies/claude-configs/tree/main/react-19/concerns/performance/skills/code-splitting
Command: npx skills add https://github.com/djankies/claude-configs --skill code-splitting

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Large JavaScript bundles slow down initial page load, impacting user experience, SEO, and overall application performance. This Skill provides strategies to reduce bundle size by loading code only when needed.

Core Features & Use Cases

  • Basic Pattern: Implement lazy loading for components using lazy() and Suspense.
  • Route-Based Splitting: Optimize initial load by splitting code per route, loading only the necessary components for the current page.
  • Component-Based Splitting: Lazy load specific components (e.g., charts, tables) only when they become visible or are explicitly requested.
  • Use Case: Implement code splitting for the /admin route in your application, ensuring the large admin dashboard component is only loaded when a user navigates to that specific route, improving initial load times for other pages.

Quick Start

Apply code splitting to the src/components/Chart.js component using lazy() and Suspense so it loads only when visible.

Frequently Asked Questions about code-splitting

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce bundle size in React applications?

Reduce bundle size by implementing code splitting with React.lazy() and Suspense, loading components only when needed. This approach delays loading of non-critical code until the user navigates to or interacts with specific routes or components, improving initial page load performance.

What's the best way to implement route-based code splitting in React?

Use React.lazy() with dynamic import() to wrap route components, then wrap your route tree in Suspense with a fallback UI. This ensures each route's code loads only when the user navigates to it, significantly reducing the initial bundle sent to the browser.

Can I lazy load individual components in React, or only entire routes?

You can lazy load both routes and individual components. Use React.lazy() and Suspense for specific components like charts or tables that aren't immediately visible, allowing fine-grained control over what loads and when, beyond route-level splitting.

Does code splitting work with React Router?

Yes, code splitting integrates seamlessly with react-router-dom. Wrap lazily-imported route components in Suspense at your route configuration level, and React Router will automatically load the code chunk only when users navigate to that route.

What performance impact does Suspense have on lazy-loaded components?

Suspense adds minimal overhead—it manages the loading state and displays a fallback UI while the code chunk downloads. The performance gain from deferring code download far outweighs this cost, especially for large components or routes users may never visit.

When should I use component-level splitting instead of route-based splitting?

Use component-level splitting for heavy, non-critical UI elements visible conditionally or below the fold—such as admin panels, modals, or data visualization components. Route-based splitting is best for separating entire pages; combine both strategies for optimal performance across your application.