home / skills / hoangnguyen0403 / agent-skills-standard / data-fetching
This skill helps you implement Next.js data fetching best practices across app router components, enabling efficient caching, revalidation, and parallel data
npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill data-fetchingReview the files below or copy the command above to add this skill to your agents.
---
name: Next.js Data Fetching
description: Fetch API, Caching, and Revalidation strategies.
metadata:
labels: [nextjs, data-fetching, caching]
triggers:
files: ['**/*.tsx', '**/service.ts']
keywords: [fetch, revalidate, no-store, force-cache]
---
# Data Fetching (App Router)
## **Priority: P0 (CRITICAL)**
Fetch data directly in Server Components using `async/await`.
## Strategies
- **Static**: Build-time. `fetch(url, { cache: 'force-cache' })`.
- **Dynamic**: Request-time. `fetch(url, { cache: 'no-store' })` or `cookies()`.
- **Revalidated**: `fetch(url, { next: { revalidate: 60 } })`.
## Patterns
- **Direct Access**: Call DB/Service layer directly. **Do not fetch your own /api routes.**
- **Colocation**: Fetch exactly where data is needed.
- **Parallel**: Use `Promise.all()` to prevent waterfalls.
- **Client-Side**: Use SWR/React Query for live/per-user data (no SEO).
## Revalidation
- **Path**: `revalidatePath('/path')` - Purge cache for a route.
- **Tag**: `revalidateTag('key')` - Purge by tag.
## Anti-Patterns
- **No Root Awaits**: Avoid blocking the entire page. Use `<Suspense>`.
- **No useEffect**: Avoid manual fetching in client effects.
- **Internal API**: Never call `/api/...` from Server Components.
## Examples & References
- [Usage Examples](references/usage-examples.md)
- [Caching Documentation](https://nextjs.org/docs/app/building-your-application/caching)
This skill documents Next.js App Router data fetching, caching, and revalidation strategies for building fast, consistent React apps. It focuses on Server Component patterns, caching options, and best practices to avoid common anti-patterns. Use it to choose the correct fetching mode and revalidation mechanism for SEO, performance, and real-time needs.
The skill explains how to fetch data directly in Server Components using async/await and how to configure caching via fetch options (static, dynamic, revalidated). It covers colocating fetch logic near UI, running parallel requests with Promise.all, and when to delegate live or per-user data to client libraries like SWR or React Query. It also details revalidation APIs (revalidatePath, revalidateTag) and which internal calls to avoid.
Can I call my internal /api routes from a Server Component?
No. Server Components should call the service or database layer directly. Calling your own /api routes adds unnecessary HTTP overhead and can defeat caching benefits.
When should I use revalidateTag versus revalidatePath?
Use revalidateTag for granular, content-oriented invalidation across pages that share data. Use revalidatePath when you need to purge a specific route’s cached output.