home / skills / openclaw / skills / lazy-loader

lazy-loader skill

/skills/lxgicstudios/lazy-loader

This skill analyzes your React bundle to identify components suitable for lazy loading and suggests optimal splitting with AI guidance.

npx playbooks add skill openclaw/skills --skill lazy-loader

Review the files below or copy the command above to add this skill to your agents.

Files (8)
SKILL.md
2.4 KB
---
name: lazy-loader
description: Identify components that should be lazy loaded using AI. Use when optimizing bundle size and initial load.
---

# Lazy Load Analyzer

Your bundle is huge and your initial load is slow. This tool finds components that should be dynamically imported and tells you exactly how to split them. Stop shipping the entire app on first load.

**One command. Zero config. Just works.**

## Quick Start

```bash
npx ai-lazy-load ./src
```

## What It Does

- Analyzes your component tree for lazy loading opportunities
- Identifies below-the-fold components that don't need immediate loading
- Finds route-based splits for Next.js and React Router
- Suggests React.lazy() implementations with Suspense boundaries
- Estimates bundle size impact for each suggestion

## Usage Examples

```bash
# Analyze all components
npx ai-lazy-load ./src/components

# Focus on pages/routes
npx ai-lazy-load ./src/pages --routes-only

# Show bundle impact estimates
npx ai-lazy-load ./src --with-sizes

# Generate ready-to-use code
npx ai-lazy-load ./src --generate-code

# Next.js specific analysis
npx ai-lazy-load ./src --framework next
```

## Best Practices

- **Don't lazy load everything** - Above-the-fold components should load immediately
- **Group related components** - Lazy load a feature module, not individual buttons
- **Add proper loading states** - Every Suspense boundary needs a fallback
- **Measure the difference** - Check your bundle analyzer before and after

## When to Use This

- Initial bundle size is over 200KB gzipped
- Lighthouse says "reduce unused JavaScript"
- Adding features and worried about bloat
- Refactoring an app to improve TTI

## Part of the LXGIC Dev Toolkit

This is one of 110+ free developer tools built by LXGIC Studios. No paywalls, no sign-ups, no API keys on free tiers. Just tools that work.

**Find more:**
- GitHub: https://github.com/LXGIC-Studios
- Twitter: https://x.com/lxgicstudios
- Substack: https://lxgicstudios.substack.com
- Website: https://lxgic.dev

## Requirements

No install needed. Just run with npx. Node.js 18+ recommended.

```bash
npx ai-lazy-load --help
```

## How It Works

The tool parses your component imports and builds a dependency graph. It identifies components that are conditionally rendered, below viewport, or behind user interactions. AI evaluates which splits give you the best performance gains with minimal complexity.

## License

MIT. Free forever. Use it however you want.

Overview

This skill helps you find which UI components and routes should be lazy loaded to reduce initial bundle size and improve time-to-interactive. It uses static analysis plus AI heuristics to recommend dynamic imports, Suspense boundaries, and route splits with estimated bundle impact. Run it with a single command and get actionable code suggestions and size estimates.

How this skill works

The tool parses your project imports and builds a component dependency graph to detect conditional renders, route boundaries, and below-the-fold usage. AI evaluates trade-offs and ranks candidates by expected size reduction and complexity cost. It can generate ready-to-use React.lazy() suggestions, Suspense boundaries, and route-based split points, with optional bundle-size estimates.

When to use it

  • Your initial bundle or main chunk is large (e.g., >200KB gzipped)
  • Lighthouse or Web Vitals report slow TTI or unused JavaScript
  • You are adding new features and want to avoid increasing initial load
  • Refactoring routes or features to improve perceived performance
  • Preparing a production build and validating code-splitting strategy

Best practices

  • Do not lazy load above-the-fold UI; keep critical path components eager
  • Group related components into feature modules rather than splitting tiny pieces
  • Provide meaningful loading fallbacks for every Suspense boundary
  • Measure before and after with a bundle analyzer or Lighthouse
  • Iterate: apply a few splits, measure impact, then refine

Example use cases

  • Scan a React app to detect pages and widgets safe for dynamic import
  • Generate React.lazy() code and Suspense wrappers for slow routes
  • Identify below-the-fold gallery or admin panels to defer until interaction
  • Produce Next.js route split suggestions for server and client bundles
  • Estimate size savings for proposed splits before committing code changes

FAQ

Does this require configuration?

No. It runs with zero config by default but accepts flags for framework hints, routes-only scans, code generation, and size estimates.

Will it break my app if I apply suggestions?

Suggestions include safe defaults like Suspense fallbacks and grouping guidance. Always run tests and manual checks after applying code changes.