nextjs-data-fetching-and-caching

Configure data fetching and caching in Next.js App Router applications.

2|Updated Dec 5, 2025
One-click install
npx skills add https://github.com/AgentiveCity/SkillFactory --skill nextjs-data-fetching-and-caching
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nextjs-data-fetching-and-caching
Source: https://github.com/AgentiveCity/SkillFactory/tree/main/.claude/skills/nextjs-data-fetching-and-caching
Command: npx skills add https://github.com/AgentiveCity/SkillFactory --skill nextjs-data-fetching-and-caching

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Designing, refactoring, and optimizing data fetching and caching in Next.js App Router projects can be complex, involving server components, route handlers, server actions, and various cache modes. This Skill streamlines the process, ensuring efficient data delivery, improved performance, and reduced development effort.

Core Features & Use Cases

  • Server-First Data Strategies: Design data-loading strategies for routes, layouts, and components using async server components and server actions for mutations.
  • Intelligent Caching & Revalidation: Configure caching (force-cache, no-store) and ISR (revalidate) for optimal data freshness and performance.
  • Efficient Data Flow: Prevent over-fetching and duplicate requests, and handle errors and loading states gracefully using loading.tsx and error.tsx.

Quick Start

Connect this dashboard route to our REST API and set it to revalidate every minute, moving client-side data fetching into server components.

Frequently Asked Questions about nextjs-data-fetching-and-caching

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up data fetching in Next.js server components?

Data fetching in Next.js server components uses async/await directly in the component body. Fetch data in server components, route handlers, or server actions, then pass results to client components. This approach keeps sensitive logic server-side and improves performance by reducing client-side data loading.

What's the difference between force-cache and no-store in Next.js?

force-cache caches fetch responses indefinitely until revalidation; no-store fetches fresh data on every request. Use force-cache for static content and no-store for real-time data. Pair with next: { revalidate } to set custom expiration times for ISR.

How do I prevent duplicate fetch requests in Next.js?

Next.js automatically deduplicates identical fetch requests during a single render pass. Configure explicit caching with cache: 'force-cache' or 'no-store' and use revalidation strategies to control when duplicates are allowed, reducing unnecessary API calls and improving performance.

Can I use server actions for data mutations in Next.js App Router?

Server actions handle mutations securely in App Router by executing server-side logic triggered from client components. Use them with forms or event handlers, combine with revalidation to refresh cached data after mutations, and maintain clear client-server boundaries.

When should I use ISR (Incremental Static Regeneration) versus on-demand revalidation?

ISR with next: { revalidate } regenerates pages at fixed intervals for predictable freshness; on-demand revalidation updates immediately when data changes. Choose ISR for content with regular update cycles and on-demand for event-driven changes or urgent updates.

What's the best way to handle loading and error states in Next.js data fetching?

Use loading.tsx for skeleton UI during fetches and error.tsx to catch and display errors gracefully. Pair with server components and async rendering to show loading states before data arrives, improving perceived performance and user experience.