nextjs-performance
Expert Next.js performance optimization skill covering Core Web Vitals, image/font optimization, caching strategies, streaming, bundle optimization, and Server Components best practices. Use when optimizing Next.js applications for Core Web Vitals (LCP, INP, CLS), implementing next/image and next/font, configuring caching with unstable_cache and revalidateTag, converting Client Components to Server Components, implementing Suspense streaming, or analyzing and reducing bundle size. Supports Next.js 16 + React 19 patterns.
What this skill does
# Next.js Performance Optimization
Expert guidance for optimizing Next.js applications with focus on Core Web Vitals, modern patterns, and best practices.
## Overview
This skill provides comprehensive guidance for optimizing Next.js applications. It covers Core Web Vitals optimization (LCP, INP, CLS), modern React patterns, Server Components, caching strategies, and bundle optimization techniques. Designed for developers already familiar with React/Next.js who want to implement production-grade optimizations.
## When to Use
Use this skill when working on Next.js applications and need to:
- Optimize Core Web Vitals (LCP, INP, CLS) for better performance and SEO
- Implement image optimization with `next/image` for faster loading
- Configure font optimization with `next/font` to eliminate layout shift
- Set up caching strategies using `unstable_cache`, `revalidateTag`, or ISR
- Convert Client Components to Server Components for reduced bundle size
- Implement Suspense streaming for progressive page loading
- Analyze and reduce bundle size with code splitting and dynamic imports
- Configure metadata and SEO for better search engine visibility
- Optimize API route handlers for better performance
- Apply Next.js 16 and React 19 modern patterns
### Coverage Areas
- **Core Web Vitals optimization** (LCP, INP, CLS)
- **Image optimization** with `next/image`
- **Font optimization** with `next/font`
- **Caching strategies** (`unstable_cache`, `revalidateTag`, ISR)
- **Server Components** patterns and Client-to-Server conversion
- **Streaming and Suspense** for progressive loading
- **Bundle optimization** and code splitting
- **Metadata and SEO** configuration
- **Route handlers** optimization
- **Next.js 16 + React 19** patterns
## Instructions
### Before Starting
1. **Analyze current performance** with Lighthouse
2. **Identify bottlenecks** - check Core Web Vitals in Chrome DevTools or PageSpeed Insights
3. **Determine optimization priority**:
- LCP issues → Focus on images, fonts
- INP issues → Reduce JS, use Server Components
- CLS issues → Add dimensions, use next/font
### How to Use This Skill
1. **Load relevant reference files** based on the area you're optimizing:
- Image issues → `references/image-optimization.md`
- Font/layout shift → `references/font-optimization.md`
- Caching → `references/caching-strategies.md`
- Component architecture → `references/server-components.md`
2. **Follow the quick patterns** for common optimizations
3. **Apply before/after conversions** to improve existing code
4. **Verify improvements** with Lighthouse after changes
### Core Principles
1. **Prefer Server Components** - Only use 'use client' when necessary (browser APIs, interactivity)
2. **Load components as low as possible** - Keep Client Components at leaf nodes
3. **Use Suspense boundaries** - Enable streaming and progressive loading
4. **Cache appropriately** - Use tags for granular revalidation
5. **Measure before/after** - Always verify improvements with real metrics
## Examples
### Example 1: Convert Client Component to Server Component
**BEFORE (Client Component with useEffect):**
```tsx
'use client'
import { useEffect, useState } from 'react'
export default function ProductList() {
const [products, setProducts] = useState([])
useEffect(() => {
fetch('/api/products').then(r => r.json()).then(setProducts)
}, [])
return <ul>{products.map(p => <li key={p.id}>{p.name}</li>)}</ul>
}
```
**AFTER (Server Component with direct data access):**
```tsx
import { db } from '@/lib/db'
export default async function ProductList() {
const products = await db.product.findMany()
return <ul>{products.map(p => <li key={p.id}>{p.name}</li>)}</ul>
}
```
### Example 2: Optimize Images for LCP
```tsx
import Image from 'next/image'
export function Hero() {
return (
<div className="relative w-full h-[600px]">
<Image
src="/hero.jpg"
alt="Hero"
fill
priority // Disable lazy loading for LCP
sizes="100vw"
className="object-cover"
/>
</div>
)
}
```
### Example 3: Implement Caching Strategy
```tsx
import { unstable_cache, revalidateTag } from 'next/cache'
// Cached data function
const getProducts = unstable_cache(
async () => db.product.findMany(),
['products'],
{ revalidate: 3600, tags: ['products'] }
)
// Revalidate on mutation
export async function createProduct(data: FormData) {
'use server'
await db.product.create({ data })
revalidateTag('products')
}
```
### Example 4: Setup Optimized Fonts
```tsx
import { Inter } from 'next/font/google'
const inter = Inter({
subsets: ['latin'],
display: 'swap',
variable: '--font-inter',
})
export default function RootLayout({ children }) {
return (
<html lang="en" className={inter.variable}>
<body className={`${inter.className} antialiased`}>
{children}
</body>
</html>
)
}
```
### Example 5: Implement Suspense Streaming
```tsx
import { Suspense } from 'react'
export default function Page() {
return (
<>
<header>Static content (immediate)</header>
<Suspense fallback={<ProductSkeleton />}>
<ProductList /> {/* Streamed when ready */}
</Suspense>
<Suspense fallback={<ReviewsSkeleton />}>
<Reviews /> {/* Independent streaming */}
</Suspense>
</>
)
}
```
## Reference Documentation
Load these references when working on specific areas:
| Topic | Reference File |
|-------|----------------|
| Core Web Vitals | `references/core-web-vitals.md` |
| Image Optimization | `references/image-optimization.md` |
| Font Optimization | `references/font-optimization.md` |
| Caching Strategies | `references/caching-strategies.md` |
| Server Components | `references/server-components.md` |
| Streaming/Suspense | `references/streaming-suspense.md` |
| Bundle Optimization | `references/bundle-optimization.md` |
| Metadata/SEO | `references/metadata-seo.md` |
| API Routes | `references/api-routes.md` |
| Next.js 16 Patterns | `references/nextjs-16-patterns.md` |
## Common Conversions
| From | To | Benefit |
|------|-----|---------|
| `useEffect` + fetch | Direct async in Server Component | -70% JS, faster TTFB |
| `useState` for data | Server Component with direct DB access | Simpler code, no hydration |
| Client-side fetch | `unstable_cache` or ISR | Faster repeated loads |
| `img` tag | `next/image` | Optimized formats, lazy loading |
| CSS font import | `next/font` | Zero CLS, automatic optimization |
| Static import of heavy component | `dynamic()` | Reduced initial bundle |
## Best Practices
### Images
- Use `next/image` for all images
- Add `priority` to LCP images only
- Provide `width` and `height` or `fill` with sizes
- Use `placeholder="blur"` for better UX
- Configure remotePatterns in next.config.js
### Fonts
- Use `next/font` instead of CSS imports
- Specify `subsets` to reduce size
- Use `display: 'swap'` for immediate text render
- Create CSS variable with `variable` option
- Configure Tailwind to use CSS variables
### Caching
- Cache expensive queries with `unstable_cache`
- Use meaningful cache tags for granular control
- Implement on-demand revalidation for dynamic content
- Set TTL based on data change frequency
- Use revalidatePath for route-level invalidation
### Components
- Convert Client Components to Server Components where possible
- Keep Client Components at the leaf level
- Use Suspense boundaries for progressive loading
- Implement proper loading states
- Use dynamic() for heavy components below the fold
### Bundle
- Lazy load heavy components with `dynamic()`
- Use named exports for better tree shaking
- Analyze bundle regularly with `@`next/bundle-analyzer
- Prefer ESM packages over CommonJS
- Use modularizeImports for large libraries
## Constraints and Warnings
### Server Components Limitations
- Cannot use browser APIs (window, localStorage, document)
- Cannot use RRelated in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.