Next.js 16 App Router
Version 0.1.0
Next.js Community
January 2026
Note:
This document is mainly for agents and LLMs to follow when maintaining,
generating, or refactoring codebases. Humans may also find it useful,
but guidance here is optimized for automation and consistency by AI-assisted workflows.
Abstract
Comprehensive performance optimization guide for Next.js 16 App Router applications, designed for AI agents and LLMs. Contains 40+ rules across 8 categories, prioritized by impact from critical (build optimization, caching strategy) to incremental (client components). Each rule includes detailed explanations, real-world examples comparing incorrect vs. correct implementations, and specific impact metrics to guide automated refactoring and code generation.
Table of Contents
- Build & Bundle Optimization — CRITICAL
- 1.1 Avoid Barrel File Imports in App Router — CRITICAL (2-10× faster dev startup)
- 1.2 Configure optimizePackageImports for Icon Libraries — CRITICAL (200-800ms faster imports, 50-80% smaller bundles)
- 1.3 Configure Server External Packages for Node Dependencies — HIGH (prevents bundling issues, faster builds)
- 1.4 Enable Turbopack File System Caching — CRITICAL (5-10× faster cold starts on large apps)
- 1.5 Use Dynamic Imports for Heavy Components — CRITICAL (30-70% smaller initial bundle)
- Caching Strategy — CRITICAL
- 2.1 Configure Fetch Cache Options Correctly — HIGH (controls data freshness per request)
- 2.2 Configure Route Segment Caching with Exports — MEDIUM-HIGH (controls caching at route level)
- 2.3 Use React cache() for Request Deduplication — HIGH (eliminates duplicate fetches per request)
- 2.4 Use revalidatePath for Route-Level Cache Invalidation — HIGH (invalidates all cached data for a route)
- 2.5 Use revalidateTag with cacheLife Profiles — CRITICAL (stale-while-revalidate behavior, instant updates)
- 2.6 Use the 'use cache' Directive for Explicit Caching — CRITICAL (eliminates implicit caching confusion, explicit control)
- Server Components & Data Fetching — HIGH
- 3.1 Avoid Client-Side Data Fetching for Initial Data — MEDIUM-HIGH (eliminates client waterfalls, better SEO)
- 3.2 Colocate Data Fetching with Components — HIGH (eliminates prop drilling, enables streaming)
- 3.3 Fetch Data in Parallel in Server Components — HIGH (eliminates server-side waterfalls, 2-5× faster)
- 3.4 Handle Server Component Errors Gracefully — MEDIUM (prevents full page crashes, better UX)
- 3.5 Stream Server Components for Progressive Loading — HIGH (faster Time to First Byte, progressive rendering)
- 3.6 Use Preload Pattern for Critical Data — MEDIUM-HIGH (starts fetches earlier in render tree)
- Routing & Navigation — HIGH
- 4.1 Configure Link Prefetching Appropriately — MEDIUM-HIGH (instant navigation for likely destinations)
- 4.2 Use Intercepting Routes for Modal Patterns — HIGH (enables shareable modal URLs, better UX)
- 4.3 Use notFound() for Missing Resources — MEDIUM (proper 404 handling, better SEO)
- 4.4 Use Parallel Routes for Independent Content — HIGH (independent loading, streaming, error handling)
- 4.5 Use proxy.ts for Network Boundary Logic — MEDIUM-HIGH (clearer network boundary, Node.js runtime)
- Server Actions & Mutations — MEDIUM-HIGH
- 5.1 Handle Server Action Errors Gracefully — MEDIUM-HIGH (prevents silent failures, better error UX)
- 5.2 Revalidate Cache After Mutations — MEDIUM (ensures fresh data after changes)
- 5.3 Show Pending States with useFormStatus — MEDIUM-HIGH (better UX during form submission)
- 5.4 Use Optimistic Updates for Instant Feedback — MEDIUM (instant UI response, better perceived performance)
- 5.5 Use Server Actions for Form Submissions — MEDIUM-HIGH (eliminates API routes, type-safe mutations)
- Streaming & Loading States — MEDIUM
- 6.1 Match Skeleton Dimensions to Actual Content — MEDIUM (prevents layout shift, better CLS score)
- 6.2 Nest Suspense for Progressive Disclosure — LOW-MEDIUM (fine-grained loading control, better UX)
- 6.3 Place Suspense Boundaries Strategically — MEDIUM (faster perceived performance, progressive loading)
- 6.4 Use error.tsx for Route-Level Error Boundaries — MEDIUM (graceful error recovery, prevents full page crashes)
- 6.5 Use loading.tsx for Route-Level Loading States — MEDIUM (automatic loading UI, instant navigation feedback)
- Metadata & SEO — MEDIUM
- 7.1 Configure Robots for Crawl Control — MEDIUM (prevents indexing of private pages)
- 7.2 Generate Dynamic OpenGraph Images — LOW-MEDIUM (better social sharing, higher CTR)
- 7.3 Generate Sitemaps Dynamically — MEDIUM (improved crawlability, faster indexing)
- 7.4 Use generateMetadata for Dynamic Metadata — MEDIUM (dynamic SEO, social sharing optimization)
- Client Components — LOW-MEDIUM
- 8.1 Avoid Hydration Mismatches — LOW-MEDIUM (prevents React warnings, ensures correct rendering)
- 8.2 Load Third-Party Scripts Efficiently — LOW-MEDIUM (prevents blocking, improves LCP)
- 8.3 Minimize 'use client' Boundary Scope — LOW-MEDIUM (reduces client JS, better performance)
- 8.4 Pass Server Components as Children to Client Components — LOW-MEDIUM (keeps static content on server, reduces bundle)
References
Source Files
This document was compiled from individual reference files. For detailed editing or extension:
| File | Description |
|---|---|
| references/_sections.md | Category definitions and impact ordering |
| assets/templates/_template.md | Template for creating new rules |
| SKILL.md | Quick reference entry point |
| metadata.json | Version and reference URLs |