agentleFS
jgamaraalvjgamaraalv/delivery-loop/.claude/skills/nextjs-performance/SKILL.md

nextjs-performance

Skill0 starsChanged 4 months agoMITView on GitHub

Next.js performance optimization for Core Web Vitals, image/font optimization, caching, streaming, bundle size, and Server Components. Use when fixing LCP/INP/CLS, implementing next/image or next/font, configuring unstable_cache, converting Client to Server Components, streaming with Suspense, or reducing bundle size. Covers Next.js 16 + React 19 patterns.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Identify bottlenecks: - check Core Web Vitals in Chrome DevTools or PageSpeed Insights

    line 11
  2. Distinctive:

    Prefer Server Components: - Only use 'use client' when necessary (browser APIs, interactivity)

    line 19
  3. Distinctive:

    Load components as low as possible: - Keep Client Components at leaf nodes

    line 20
  4. Distinctive:

    Cache appropriately: - Use tags for granular revalidation

    line 22
  5. Distinctive:

    Measure before/after: - Always verify improvements with real metrics

    line 23

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Next.js Performance Optimization

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

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

References

Each file is loaded on demand — read one only when the task needs that depth (progressive disclosure).

  • references/core-web-vitals.md — LCP/INP/CLS targets, diagnostics, and per-metric optimizations · read when measuring or fixing Core Web Vitals.
  • references/image-optimization.md — next/image sizing, priority, blur placeholder, remotePatterns config · read when fixing LCP or image-related CLS.
  • references/font-optimization.md — next/font setup, subsets, display swap, CSS variable integration · read when eliminating font-related CLS or FOUT.
  • references/caching-strategies.md — unstable_cache, revalidateTag/Path, ISR, cache tags, TTL guidance · read when configuring data or route caching.
  • references/server-components.md — Client-to-Server conversion patterns, RSC constraints, Suspense boundaries · read when moving components server-side or wiring streaming.
  • references/streaming-suspense.md — Suspense boundaries, progressive loading, fallback skeletons · read when implementing streaming or reducing TTFB.
  • references/bundle-optimization.md — dynamic(), code splitting, tree shaking, modularizeImports, bundle-analyzer · read when reducing initial JS bundle size.
  • references/metadata-seo.md — static/generateMetadata, Open Graph, canonical, sitemap · read when configuring metadata or SEO.
  • references/api-routes.md — Route Handler patterns, Edge runtime, input validation, error handling · read when optimizing API routes.
  • references/nextjs-16-patterns.md — async params Promise, use() hook, useOptimistic, React 19 patterns · read when adopting Next.js 15+/React 19 APIs.

Common Conversions

FromToBenefit
useEffect + fetchDirect async in Server Component-70% JS, faster TTFB
useState for dataServer Component with direct DB accessSimpler code, no hydration
Client-side fetchunstable_cache or ISRFaster repeated loads
img tagnext/imageOptimized formats, lazy loading
CSS font importnext/fontZero CLS, automatic optimization
Static import of heavy componentdynamic()Reduced initial bundle

Constraints and Warnings

Server Components Limitations

  • Cannot use browser APIs (window, localStorage, document)
  • Cannot use React hooks (useState, useEffect, useContext)
  • Cannot use event handlers (onClick, onSubmit)
  • Cannot use dynamic imports with ssr: false

Image Optimization Constraints

  • priority should only be used for above-the-fold images
  • External images require configuration in next.config.js
  • width and height are required unless using fill
  • Animated GIFs are not optimized by default

Caching Considerations

  • Cache tags must be manually invalidated
  • Data cache is per-request in development
  • Edge runtime has different caching behavior
  • Be careful caching user-specific data

Bundle Size Warnings

  • Dynamic imports can impact SEO if critical content
  • Tree shaking requires proper ES module usage
  • Some libraries cannot be tree shaken (avoid barrel exports)
  • Client Components increase bundle size - use sparingly

Performance Checklist

  • All images use next/image with proper dimensions
  • LCP images have priority attribute
  • Fonts use next/font with subsets
  • Server Components used where possible
  • Client Components at leaf level only
  • Suspense boundaries for data fetching
  • Caching configured for expensive operations
  • Bundle analyzed for duplicates
  • Heavy components lazy loaded
  • Lighthouse score verified before/after

Common Mistakes

// ❌ 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

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.