# Nextjs

> Next.js framework best practices including App Router, data fetching, and performance optimization. Use when this capability is needed.

- Skill: `tomevault-io/nextjs` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/nextjs`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/nextjs/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/nextjs

---


# Next.js Best Practices

## App Router (v13+)
- Use Server Components by default
- Add 'use client' only when needed
- Use loading.tsx for loading states
- Use error.tsx for error boundaries
- Use layout.tsx for shared layouts
- Use route groups (folder) for organization

## Data Fetching
- Fetch in Server Components when possible
- Use React Suspense for streaming
- Use generateStaticParams for static generation
- Use revalidate for ISR
- Use Next.js cache() for request deduplication

## Performance
- Use next/image for optimized images
- Use next/font for font optimization
- Use next/link for client-side navigation
- Implement proper caching headers
- Use dynamic imports for code splitting

## API Routes
- Use Route Handlers in app directory
- Validate inputs thoroughly
- Handle errors gracefully
- Use middleware for auth/logging

## SEO
- Use generateMetadata for dynamic SEO
- Implement proper Open Graph tags
- Use semantic HTML
- Add structured data (JSON-LD)

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/kprsnt2) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-15 -->

