Install any skill in seconds. Free to start, no credit card required.
Get Started Free →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.
.claude/skills/giuseppe-trisciuoglio-nextjs-performance/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 116% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 140% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 122% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 565% | 0% |
| case-05 | ✓→✓ | = Same ✓ | 286% | 0% |
Expert guidance for optimizing Next.js applications with focus on Core Web Vitals, modern patterns, and best practices.
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.
Use this skill when working on Next.js applications and need to:
next/image for faster loadingnext/font to eliminate layout shiftunstable_cache, revalidateTag, or ISRnext/imagenext/fontunstable_cache, revalidateTag, ISR)references/image-optimization.mdreferences/font-optimization.mdreferences/caching-strategies.mdreferences/server-components.mdBEFORE (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):
tsximport { 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> }
tsximport 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> ) }
tsximport { 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') }
tsximport { 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> ) }
tsximport { 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> </> ) }
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 |
| 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 |
next/image for all imagespriority to LCP images onlywidth and height or fill with sizesplaceholder="blur" for better UXnext/font instead of CSS importssubsets to reduce sizedisplay: 'swap' for immediate text rendervariable optionunstable_cachedynamic()@next/bundle-analyzerpriority should only be used for above-the-fold imageswidth and height are required unless using filltsx// Next.js 15+ params is a Promise export default async function Page({ params, }: { params: Promise<{ slug: string }> }) { const { slug } = await params const post = await fetchPost(slug) return <article>{post.content}</article> }
tsx'use client' import { use, Suspense } from 'react' function Comments({ promise }: { promise: Promise<Comment[]> }) { const comments = use(promise) // Suspend until resolved return <ul>{comments.map(c => <li key={c.id}>{c.text}</li>)}</ul> }
tsx'use client' import { useOptimistic } from 'react' export function TodoList({ todos }: { todos: Todo[] }) { const [optimisticTodos, addOptimisticTodo] = useOptimistic( todos, (state, newTodo: Todo) => [...state, newTodo] ) async function addTodo(formData: FormData) { const text = formData.get('text') as string addOptimisticTodo({ id: crypto.randomUUID(), text, completed: false }) await createTodo(text) } return ( <form action={addTodo}> <input name="text" /> {optimisticTodos.map(todo => <div key={todo.id}>{todo.text}</div>)} </form> ) }
bash# Install analyzer npm install --save-dev @next/bundle-analyzer # Run analysis ANALYZE=true npm run build
javascript// next.config.js const withBundleAnalyzer = require('@next/bundle-analyzer')({ enabled: process.env.ANALYZE === 'true', }) module.exports = withBundleAnalyzer({ modularizeImports: { 'lodash': { transform: 'lodash/{{member}}' }, }, })
next/image with proper dimensionspriority attributenext/font with subsetstsx// ❌ DON'T: Fetch in useEffect 'use client' useEffect(() => { fetch('/api/data').then(...) }, []) // ✅ DO: Fetch directly in Server Component const data = await fetch('/api/data') // ❌ DON'T: Forget dimensions on images <Image src="/photo.jpg" /> // ✅ DO: Always provide dimensions <Image src="/photo.jpg" width={800} height={600} /> // ❌ DON'T: Use priority on all images <Image src="/photo1.jpg" priority /> <Image src="/photo2.jpg" priority /> // ✅ DO: Priority only for LCP <Image src="/hero.jpg" priority /> <Image src="/photo.jpg" loading="lazy" /> // ❌ DON'T: Cache everything with same TTL { revalidate: 3600 } // ✅ DO: Match TTL to data change frequency { revalidate: 86400 } // Categories rarely change { revalidate: 60 } // Comments change often
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-04 | pass→pass | 8,639 | 6,722 | -22% | 1 | 1 | 0% | 1,848 | 4,438 | +140% | 0 | 0 | — |
case-01 | fail→pass | 11,348 | 7,420 | -35% | 1 | 1 | 0% | 2,054 | 4,445 | +116% | 0 | 0 | — |
case-02 | pass→pass | 10,562 | 8,126 | -23% | 1 | 1 | 0% | 2,056 | 4,558 | +122% | 0 | 0 | — |
case-03 | pass→pass | 3,573 | 3,633 | +2% | 1 | 1 | 0% | 567 | 3,769 | +565% | 0 | 0 | — |
case-05 | pass→pass | 6,031 | 7,123 | +18% | 1 | 1 | 0% | 1,164 | 4,489 | +286% | 0 | 0 | — |
case-06 | pass→pass | 4,276 | 4,665 | +9% | 1 | 1 | 0% | 796 | 4,061 | +410% | 0 | 0 | — |
case-07 | pass→pass | 11,536 | 10,251 | -11% | 1 | 1 | 0% | 2,241 | 5,106 | +128% | 0 | 0 | — |
case-08 | pass→pass | 5,007 | 5,125 | +2% | 1 | 1 | 0% | 921 | 4,194 | +355% | 0 | 0 | — |
case-09 | pass→pass | 6,576 | 4,281 | -35% | 1 | 1 | 0% | 1,271 | 3,892 | +206% | 0 | 0 | — |
case-10 | pass→pass | 12,444 | 9,268 | -26% | 1 | 1 | 0% | 2,343 | 4,981 | +113% | 0 | 0 | — |
case-11 | pass→pass | 8,217 | 6,120 | -26% | 1 | 1 | 0% | 1,626 | 4,261 | +162% | 0 | 0 | — |
case-12 | pass→pass | 9,460 | 6,823 | -28% | 1 | 1 | 0% | 1,891 | 4,418 | +134% | 0 | 0 | — |
case-13 | pass→pass | 10,817 | 8,440 | -22% | 1 | 1 | 0% | 2,073 | 4,769 | +130% | 0 | 0 | — |
case-14 | pass→pass | 11,320 | 8,013 | -29% | 1 | 1 | 0% | 2,054 | 4,764 | +132% | 0 | 0 | — |
case-15 | pass→pass | 9,917 | 6,487 | -35% | 1 | 1 | 0% | 1,806 | 4,274 | +137% | 0 | 0 | — |
case-16 | pass→pass | 11,591 | 12,243 | +6% | 1 | 1 | 0% | 2,178 | 5,407 | +148% | 0 | 0 | — |
case-17 | pass→pass | 10,922 | 9,970 | -9% | 1 | 1 | 0% | 2,085 | 5,027 | +141% | 0 | 0 | — |
case-18 | pass→pass | 4,139 | 3,739 | -10% | 1 | 1 | 0% | 712 | 3,765 | +429% | 0 | 0 | — |
case-19 | pass→pass | 5,073 | 4,296 | -15% | 1 | 1 | 0% | 948 | 3,928 | +314% | 0 | 0 | — |
case-20 | pass→pass | 13,781 | 11,189 | -19% | 1 | 1 | 0% | 2,809 | 5,358 | +91% | 0 | 0 | — |
case-21 | pass→pass | 11,499 | 11,544 | +0% | 1 | 1 | 0% | 2,347 | 5,401 | +130% | 0 | 0 | — |
case-22 | pass→pass | 3,962 | 4,350 | +10% | 1 | 1 | 0% | 736 | 3,901 | +430% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +5 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.