Skip to main content
skill CX Codex

web-performance-optimization · secondsky — Claude Code skill: speed up web apps

A skill that walks your agent through code splitting, lazy loading, caching and Core Web Vitals monitoring for web apps.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add secondsky/claude-skills --skill web-performance-optimization -a claude-code
Open on GitHub

What web-performance-optimization does

The skill hands your agent concrete patterns for cutting page load time. Inside: React.lazy and Suspense for routes, a splitChunks config that pulls node_modules into a vendors chunk, responsive images with <picture> and srcset, and a service worker that caches static assets.

There is a separate section on measuring Core Web Vitals. The agent wires up PerformanceObserver for LCP, CLS and INP, and metrics go to your analytics through a placeholder sendToAnalytics function you have to fill in yourself. The target table lists LCP under 2.5s, INP under 200ms and CLS under 0.1. INP replaced FID as a Core Web Vital in March 2024, so if your dashboards still track FID, that is worth fixing.

Compression examples cover Nginx, and a seven-item checklist rounds things out. Extra material lives in references/compression-monitoring.md and references/typescript-advanced.md: Apache config, TTFB monitoring and Puppeteer automation for measurements. The skill does not optimize anything on its own. It gives the agent templates, and the architecture calls stay with you.

What it helps with

  • split a bundle by route and move vendors into their own chunk
  • lazy load components below the fold
  • add a service worker that caches static assets
  • collect LCP, CLS and INP and ship them to analytics
  • turn on gzip in Nginx to shrink responses

Example prompts for the agent

  • Split my app routes into lazy chunks with React.lazy and Suspense
  • Configure splitChunks in webpack so node_modules goes into a separate vendors chunk
  • Add PerformanceObserver tracking for LCP, CLS and INP and send the metrics to my analytics

How to install web-performance-optimization

1Skills CLI (Vercel)

npx skills add secondsky/claude-skills --skill web-performance-optimization -a claude-code

2Manually: put the files in place

~/.claude/skills/web-performance-optimization/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/web-performance-optimization/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about web-performance-optimization

How do I install web-performance-optimization in Claude?

Run npx skills add secondsky/claude-skills --skill web-performance-optimization -a claude-code. The skill lands in ~/.claude/skills/web-performance-optimization/SKILL.md.

What does web-performance-optimization do?

It gives the agent templates for code splitting, lazy loading, caching and compression, plus code to measure Core Web Vitals.

Which metrics does the skill track?

LCP, CLS and INP. INP replaced FID as a Core Web Vital in March 2024, so FID numbers no longer reflect page responsiveness.

Source text

SKILL.md · MIT
---
name: web-performance-optimization
description: Optimizes web application performance through code splitting, lazy loading, caching strategies, and Core Web Vitals monitoring. Use when improving page load times, implementing service workers, or reducing bundle sizes.
license: MIT
---

# Web Performance Optimization

## Overview

Implement performance optimization strategies including lazy loading, code splitting, caching, compression, and monitoring to improve Core Web Vitals and user experience.

## When to Use

- Slow page load times
- High Largest Contentful Paint (LCP)
- Large bundle sizes
- Frequent Cumulative Layout Shift (CLS)
- Mobile performance issues

## Code Splitting (React)

```javascript
import { lazy, Suspense } from 'react';
import { Routes, Route } from 'react-router-dom';

const Home = lazy(() => import('./pages/Home'));
const Dashboard = lazy(() => import('./pages/Dashboard'));
const Settings = lazy(() => import('./pages/Settings'));

function App() {
  return (
    <Suspense fallback={<Loading />}>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/dashboard" element={<Dashboard />} />
        <Route path="/settings" element={<Settings />} />
      </Routes>
    </Suspense>
  );
}
```

## Webpack Bundle Optimization

```javascript
// webpack.config.js
module.exports = {
  optimization: {
    splitChunks: {
      chunks: 'all',
      cacheGroups: {
        vendor: {
          test: /[\\/]node_modules[\\/]/,
          name: 'vendors',
          chunks: 'all'
        }
      }
    }
  }
};
```

## Image Optimization

```html
<picture>
  <source srcset="image.webp" type="image/webp">
  <source srcset="image.jpg" type="image/jpeg">
  <img
    src="image.jpg"
    srcset="image-400.jpg 400w, image-800.jpg 800w, image-1200.jpg 1200w"
    sizes="(max-width: 600px) 100vw, 50vw"
    loading="lazy"
    decoding="async"
    alt="Description"
  >
</picture>
```

## Service Worker Caching

```javascript
// sw.js
const CACHE_NAME = 'app-v1';
const ASSETS = ['/', '/index.html', '/main.js', '/styles.css'];

self.addEventListener('install', (event) => {
  event.waitUntil(
    caches.open(CACHE_NAME).then(cache => cache.addAll(ASSETS))
  );
});

self.addEventListener('fetch', (event) => {
  event.respondWith(
    caches.match(event.request).then(cached => {
      return cached || fetch(event.request).then(response => {
        return caches.open(CACHE_NAME).then(cache => {
          cache.put(event.request, response.clone());
          return response;
        });
      });
    })
  );
});
```

## Core Web Vitals Monitoring

```javascript
// Track LCP, CLS, INP (Note: INP replaced FID as of March 2024)
// sendToAnalytics is a placeholder function that sends metrics to your analytics endpoint
// Expected signature: sendToAnalytics({ metric: string, value: number }) => void
// Example implementation:
function sendToAnalytics({ metric, value }) {
  // Replace with your analytics implementation (e.g., Google Analytics, Segment)
  fetch('/api/analytics', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ metric, value, timestamp: Date.now() })
  });
}

// Largest Contentful Paint (LCP)
new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) {
    console.log(`LCP: ${entry.startTime}ms`);
    sendToAnalytics({ metric: 'LCP', value: entry.startTime });
  }
}).observe({ type: 'largest-contentful-paint', buffered: true });

// Cumulative Layout Shift (CLS)
new PerformanceObserver((list) => {
  let cls = 0;
  for (const entry of list.getEntries()) {
    if (!entry.hadRecentInput) cls += entry.value;
  }
  sendToAnalytics({ metric: 'CLS', value: cls });
}).observe({ type: 'layout-shift', buffered: true });

// Interaction to Next Paint (INP) - replaces FID
new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) {
    // INP measures responsiveness - duration of slowest interaction
    const inp = entry.processingEnd - entry.processingStart;
    console.log(`INP: ${inp}ms`);
    sendToAnalytics({ metric: 'INP', value: inp });
  }
}).observe({ type: 'event', buffered: true }); // 'event' captures interaction events
```

## Performance Targets

| Metric | Good | Needs Improvement |
|--------|------|-------------------|
| LCP | <2.5s | 2.5-4s |
| INP | <200ms | 200-500ms |
| CLS | <0.1 | 0.1-0.25 |
| TTI | <3.8s | 3.8-7.3s |

**Note:** INP (Interaction to Next Paint) replaced FID (First Input Delay) as a Core Web Vital in March 2024. INP provides a more comprehensive measure of page responsiveness by capturing the full duration of interactions, not just the input delay.

## Compression (Nginx)

```nginx
gzip on;
gzip_types text/plain text/css application/json application/javascript;
gzip_min_length 1000;
gzip_comp_level 6;
```

## Best Practices

- Minimize bundle size with code splitting
- Optimize images with appropriate formats
- Implement lazy loading strategically
- Use HTTP caching headers
- Enable gzip/brotli compression
- Monitor Core Web Vitals continuously
- Implement service workers
- Defer non-critical JavaScript
- Optimize critical rendering path
- Test on real devices and networks

## Optimization Checklist

- [ ] Enable code splitting for routes
- [ ] Lazy load below-fold components
- [ ] Optimize and compress images
- [ ] Implement service worker caching
- [ ] Enable gzip/brotli compression
- [ ] Monitor Core Web Vitals
- [ ] Minimize render-blocking resources

## Additional Configuration

See [references/compression-monitoring.md](references/compression-monitoring.md) for:
- Webpack compression plugin setup
- Apache .htaccess compression config
- TTFB monitoring implementation
- Puppeteer automation for measurement

See [references/typescript-advanced.md](references/typescript-advanced.md) for:
- TypeScript lazyLoad utility
- TypeScript image component
- Advanced service worker with offline fallback
- TerserPlugin configuration
- Complete PerformanceMetrics interface

## Tools

- Lighthouse / PageSpeed Insights
- WebPageTest
- Chrome DevTools Performance tab
- web-vitals npm package

## Resources

- [Web Vitals](https://web.dev/vitals/)
- [Google PageSpeed Insights](https://pagespeed.web.dev/)
- [Lighthouse](https://developers.google.com/web/tools/lighthouse)
- [WebPageTest](https://www.webpagetest.org/)
- [Performance API](https://developer.mozilla.org/en-US/docs/Web/API/Performance)

© secondsky · MIT · secondsky/claude-skills

Similar skills

Everything for Frontend and UI →

web-performance-optimization by other authors comes first.

web-performance-optimization aj-geddes A skill for speeding up web apps: code splitting, lazy loading, caching, compression and monitoring. Useful when pages load slowly. CX Codex +1 482installs web-performance-optimization davila7 A Claude skill that walks through why a site loads slowly and fixes the bottlenecks step by step. 3,490installs react-performance-optimization NickCrew Guides React rendering optimization, memoization, code splitting, and list virtualization. Useful when diagnosing slow components or trimming initial bundle size. CX Codex +1 1,900installs web-performance-audit aj-geddes This skill measures page load times, finds bottlenecks and points at what to fix. Useful after a big release or when users complain about slowness. CX Codex +1 543installs performance-optimization addyosmani An agent skill that measures before it changes code: Core Web Vitals budgets, N+1 queries, missing indexes and slow endpoints. CX Codex +1 65,200installs nextjs-performance giuseppe-trisciuoglio A Next.js optimization skill: Core Web Vitals, images and fonts, caching, streaming, bundle size. Useful when pages feel slow and you need a starting point. CX Codex +1 4,900installs vite-bundle-optimization patterns.dev A skill with bundle and build optimization patterns for Vite + React. Useful when builds drag or chunks come out larger than expected. CX Codex +1 667installs pwa-development alinaqi A skill for building Progressive Web Apps: manifest, service worker, caching strategies and offline mode. Useful when the app has to install on a phone and open without a network. CX Codex +1 4,100installs

From the same set89

motion A skill that feeds your agent the Motion (Framer Motion) docs for React: drag-and-drop, scroll effects, layout transitions. Useful when the agent guesses at props. CX Codex +1 1,100installs playwright A Playwright skill for browser automation and end-to-end testing. It finds your running dev server and writes the test script for the task. CX Codex +1 1,000installs api-testing A skill that gets your agent writing HTTP API tests: Supertest for TypeScript, httpx and pytest for Python. Covers REST, GraphQL and error handling. CX Codex +1 890installs rest-api-design This skill hands your agent a set of REST conventions: resource names, HTTP methods, status codes and JSON response shape. Useful when you start a new API or want existing endpoints to match. CX Codex +1 586installs api-authentication A skill that helps your coding agent write API authentication: JWT, OAuth 2.0, API keys, sessions and security headers. CX Codex +1 533installs web-performance-audit A skill that audits page speed: pulls Core Web Vitals, finds bottlenecks and points at what to fix. Useful when LCP or CLS drifts out of range. CX Codex +1 526installs kpi-dashboard-design A skill that guides the agent through KPI dashboard design: metric choice, layout, chart types and status colors. Useful when you build analytics views for leadership. CX Codex +1 507installs bun-sveltekit Tells the agent how to build and run SvelteKit apps on Bun: SSR, adapters, bun:sqlite and file handling. CX Codex +1 499installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor