Chapter
14 · Next.js 16: cache, PPR, proxy, AI
Next.js 16-specific features: use cache, Partial Prerendering, proxy.ts, and first-class AI agent support.
use cache — Granular Caching Directive
"use cache"is a per-function/component caching directive that replaces ad-hocunstable_cacheusage.- Cache tags are specified at the call site:
revalidateTag("my-tag")busts only tagged entries. - Use for: expensive computations, stable DB queries, API responses that change infrequently.
- Do NOT use for: user-specific data (sessions, profiles), real-time availability, mutation results.
- Pattern: tag aggressively at granular scope; revalidate precisely.
PPR (Partial Prerendering)
- PPR combines static + dynamic content in the same page — the shell is pre-rendered at build time, dynamic holes fill on request.
- Enabled via
next.config.tsand Suspense boundaries that mark dynamic regions. - Great for: marketing pages with live pricing, city pages with static hero + dynamic availability.
- Co-locates naturally with the existing pattern: Server Page fetches static + dynamic data; Streaming Suspense for dynamic sections.
proxy.ts — Request Interception
proxy.tsreplacesmiddleware.tsas the first interception point for every request.- Location: project root or
src/proxy.tsalongsidelayout.tsx. - Use for: domain-based routing (multi-tenant), redirects, rewrite rules, shared response headers.
- Do NOT use for: auth verification (use Server Actions), data fetch (use entity actions), Prisma (never from proxy).
- Runs before rendering; keep it stateless, fast, and zero-config-dependent at request time.
AI Agent Integration — agents.md, MCP, DevTools
- Next.js 16+ ships a bundled
node_modules/next/agents.mdwith version-matched framework docs for AI tools. - Rule: before using a Next.js API (caching, server actions, route handlers),
grepthe installedagents.mdfor current conventions — never rely on training data for framework APIs. - MCP servers (Supabase, Prisma, Stripe) encode API surfaces + security policies into tool definitions — prefer them over raw codegen.
- Browser log forwarding and DevTools MCP give AI agents runtime visibility into client errors.
- The
.next-dev.lockfile prevents concurrent dev servers — always check for stale locks beforenpm run dev.
Quick Rules
- Prefer
"use cache"+ tags overunstable_cache. Tag granularly; revalidate precisely. - PPR for hybrid static/dynamic pages: static shell + Suspense-bounded dynamic holes.
- proxy.ts for routing/rewrites only — never auth or data fetch.
- Check
node_modules/next/agents.mdfor current API shapes before coding. - Prefer MCP tools over raw codegen for external services (DB, Stripe).