0Pricing
Next.js 15 Fullstack (App Router + Server Actions) · 강의

선택적 제외: 동적 렌더링과 no-store

캐싱이 적절하지 않을 때 쿠키, 헤더 및 no-store 지시어로 동적 동작을 강제하는 방법을 배웁니다.

선택적 제외: 동적 렌더링과 no-store은(는) CoddyKit의 무료 Next.js 15 Fullstack (App Router + Server Actions) 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Next.js 15 Fullstack (App Router + Server Actions) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Next.js 15 Fullstack (App Router + Server Actions) 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

When Caching Is Wrong

By default, Next.js 15 tries to make your routes static at build time and cache data aggressively. That is great for marketing pages, but wrong for things that must reflect the current request.

  • A dashboard showing the logged-in user's data
  • A page that reads the request's cookies() or headers()
  • Prices, inventory, or notifications that change every second

This lesson is about opting out of caching: forcing dynamic rendering and disabling fetch caching with no-store.

Static vs Dynamic Rendering

A route is rendered in one of two modes:

  • Static: rendered once (at build, or in the background) and the HTML/data is reused for everyone.
  • Dynamic: rendered fresh on every request, so it can read per-request input.

Next.js decides automatically. The moment your code touches a Dynamic API (cookies(), headers(), searchParams) or an uncached fetch, the route switches to dynamic. You rarely flip it manually — you opt out of caching and the renderer follows.

cookies() Forces Dynamic

Reading cookies() inside a Server Component signals that the output depends on the incoming request. In Next.js 15 these APIs are async — you must await them.

Touching cookies() at all moves the route to dynamic rendering. There is no way to read a cookie statically, because a static page has no request to read from.

import { cookies } from 'next/headers';

export default async function DashboardPage() {
  const cookieStore = await cookies();
  const theme = cookieStore.get('theme')?.value ?? 'light';

  // Reading cookies() opts this page out of static rendering
  return <main data-theme={theme}>Welcome back</main>;
}

headers() Forces Dynamic Too

Like cookies, headers() is async in Next.js 15 and reading it forces dynamic rendering. Use it when output depends on request headers such as Authorization, User-Agent, or a geo header from your CDN.

Because the header value is per-request, the page can never be cached as a single static HTML for all users.

import { headers } from 'next/headers';

export default async function GreetingPage() {
  const headerList = await headers();
  const country = headerList.get('x-vercel-ip-country') ?? 'unknown';

  return <h1>Hello from {country}</h1>;
}

fetch with cache: 'no-store'

Next.js extends the native fetch with caching options. By default a fetch result may be cached, which is wrong for always-fresh data.

Pass cache: 'no-store' to bypass the cache entirely. Every render performs a real network request, and the route becomes dynamic.

  • cache: 'no-store' → never cache, always refetch
  • cache: 'force-cache' → cache indefinitely (the old default)
async function getLivePrice(symbol: string) {
  const res = await fetch(`https://api.example.com/price/${symbol}`, {
    cache: 'no-store',
  });
  return res.json() as Promise<{ price: number }>;
}

export default async function PricePage() {
  const { price } = await getLivePrice('BTC');
  return <p>Current price: {price}</p>;
}

next: { revalidate: 0 } Is the Same

There are two equivalent ways to disable caching on a single fetch:

  • { cache: 'no-store' }
  • { next: { revalidate: 0 } }

Both mean "do not serve this from cache." Prefer cache: 'no-store' for readability. Do not combine cache: 'force-cache' with revalidate: 0 — those conflict, and Next.js will warn.

// These two calls behave identically
await fetch(url, { cache: 'no-store' });
await fetch(url, { next: { revalidate: 0 } });

Route Segment: dynamic = 'force-dynamic'

Instead of opting out per fetch, you can opt out for an entire route segment using the route segment config. Exporting dynamic = 'force-dynamic' from a page.tsx or layout.tsx forces every render to be dynamic and disables the data cache for that segment.

Use this when most data on the page must be fresh, so you do not have to annotate each fetch individually.

// app/feed/page.tsx
export const dynamic = 'force-dynamic';

export default async function FeedPage() {
  // No need for cache: 'no-store' on each fetch —
  // the whole segment is dynamic
  const res = await fetch('https://api.example.com/feed');
  const items = await res.json();
  return <ul>{items.map((i: { id: string; text: string }) => <li key={i.id}>{i.text}</li>)}</ul>;
}

fetchCache: 'default-no-store'

A subtler knob is fetchCache. Setting fetchCache = 'default-no-store' changes the default for every fetch in the segment to no-store, while still letting an individual fetch opt back in with cache: 'force-cache'.

This is handy for an authenticated area where almost everything is per-user, but a few public lookups can still be cached.

// app/(app)/layout.tsx
export const fetchCache = 'default-no-store';

// Now any plain fetch() in this segment defaults to no-store.
// Opt back in explicitly when you want caching:
// await fetch(url, { cache: 'force-cache' });

Dynamic APIs in Route Handlers

Route Handlers (route.ts) follow the same rules. A GET handler can be cached unless it reads a Dynamic API or you opt out.

Reading request.url search params, or calling cookies()/headers(), makes the handler dynamic. You can also force it with export const dynamic = 'force-dynamic'.

// app/api/me/route.ts
import { cookies } from 'next/headers';
import { NextResponse } from 'next/server';

export const dynamic = 'force-dynamic';

export async function GET() {
  const session = (await cookies()).get('session')?.value;
  if (!session) {
    return NextResponse.json({ error: 'unauthorized' }, { status: 401 });
  }
  return NextResponse.json({ user: session });
}

Server Actions Are Always Dynamic

Server Actions run in response to a user interaction, so they are inherently dynamic — they are never statically cached. They read the cache and can invalidate it, but the action body itself always executes fresh.

After mutating data in an action, call revalidatePath or revalidateTag so cached pages refetch. The action does not need no-store itself.

'use server';
import { revalidatePath } from 'next/cache';

export async function addComment(postId: string, text: string) {
  await db.comment.create({ data: { postId, text } });
  // Force the post page to refetch its (otherwise cached) data
  revalidatePath(`/posts/${postId}`);
}

Don't Reach for no-store Too Early

Opting out of caching is a real performance cost: every request hits your origin and database. Before forcing dynamic everywhere, ask whether time-based revalidation would do.

  • Data fresh within a few seconds → next: { revalidate: 5 }
  • Data must reflect this exact request → no-store / dynamic
  • Data changes on a known event → cache + revalidateTag on mutation

Use no-store when correctness truly depends on per-request freshness — not as a reflex to "make it work."

Quick Check

Test your understanding of opting out of caching in Next.js 15.

Recap

You learned how to opt out of caching when it would be wrong:

  • Dynamic APIs — awaiting cookies() or headers() automatically forces dynamic rendering.
  • Per-fetch — cache: 'no-store' (or next: { revalidate: 0 }) skips the data cache.
  • Per-segment — export const dynamic = 'force-dynamic' makes the whole route dynamic; fetchCache = 'default-no-store' changes the default per fetch.
  • Route Handlers follow the same rules; Server Actions are always dynamic and invalidate caches with revalidatePath/revalidateTag.
  • Restraint — prefer time-based or tag-based revalidation; reach for no-store only when correctness needs per-request freshness.

자주 묻는 질문

“선택적 제외: 동적 렌더링과 no-store” 강의는 무료인가요?

네 — “선택적 제외: 동적 렌더링과 no-store” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Next.js 15 Fullstack (App Router + Server Actions) 강의 전체를 잠금 해제할 수 있습니다. Next.js 15 Fullstack (App Router + Server Actions) 강의에는 총 4개의 강의가 포함되어 있습니다.

“선택적 제외: 동적 렌더링과 no-store”에서 뭘 배우나요?

캐싱이 적절하지 않을 때 쿠키, 헤더 및 no-store 지시어로 동적 동작을 강제하는 방법을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Next.js 15 Fullstack (App Router + Server Actions)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Next.js 15 Fullstack (App Router + Server Actions)을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Next.js 15 Fullstack (App Router + Server Actions)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“선택적 제외: 동적 렌더링과 no-store” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Next.js 15 Fullstack (App Router + Server Actions) 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Next.js 15 Fullstack (App Router + Server Actions) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 네 가지 캐시: 요청, 데이터, 전체 경로와 라우터
  2. 시간 기반 및 주문형 재검증 전략
  3. 세밀한 캐시 무효화를 위한 태그 기반 무효화
  4. 선택적 제외: 동적 렌더링과 no-store
← Next.js 15 Fullstack (App Router + Server Actions)(으)로 돌아가기