Code splitting and lazy loading with React.lazy, Suspense, route-based splitting, intersection observer, and preload strategies for optimal bundle performance. Use when implementing lazy loading or preloading.
View on GitHubyonatangross/skillforge-claude-plugin
orchestkit-complete
January 23, 2026
Select agents to install to:
npx add-skill https://github.com/yonatangross/skillforge-claude-plugin/blob/main/./skills/lazy-loading-patterns/SKILL.md -a claude-code --skill lazy-loading-patternsInstallation paths:
.claude/skills/lazy-loading-patterns/# Lazy Loading Patterns
Code splitting and lazy loading patterns for React 19 applications using `React.lazy`, `Suspense`, route-based splitting, and intersection observer strategies.
## Overview
- Reducing initial bundle size for faster page loads
- Route-based code splitting in SPAs
- Lazy loading heavy components (charts, editors, modals)
- Below-the-fold content loading
- Conditional feature loading based on user permissions
- Progressive image and media loading
## Core Patterns
### 1. React.lazy + Suspense (Standard Pattern)
```tsx
import { lazy, Suspense } from 'react';
// Lazy load component - code split at this boundary
const HeavyEditor = lazy(() => import('./HeavyEditor'));
function EditorPage() {
return (
<Suspense fallback={<EditorSkeleton />}>
<HeavyEditor />
</Suspense>
);
}
// With named exports (requires intermediate module)
const Chart = lazy(() =>
import('./charts').then(module => ({ default: module.LineChart }))
);
```
### 2. React 19 `use()` Hook (Modern Pattern)
```tsx
import { use, Suspense } from 'react';
// Create promise outside component
const dataPromise = fetchData();
function DataDisplay() {
// Suspense-aware promise unwrapping
const data = use(dataPromise);
return <div>{data.title}</div>;
}
// Usage with Suspense
<Suspense fallback={<Skeleton />}>
<DataDisplay />
</Suspense>
```
### 3. Route-Based Code Splitting (React Router 7.x)
```tsx
import { lazy } from 'react';
import { createBrowserRouter, RouterProvider } from 'react-router';
// Lazy load route components
const Dashboard = lazy(() => import('./pages/Dashboard'));
const Settings = lazy(() => import('./pages/Settings'));
const Analytics = lazy(() => import('./pages/Analytics'));
const router = createBrowserRouter([
{
path: '/',
element: <Layout />,
children: [
{ path: 'dashboard', element: <Dashboard /> },
{ path: 'settings', element: <Settings /> },
{ path: 'analytics', element: <Analytics /> },
],