fetch() (extended)
Next.js extends the native fetch with caching and revalidation options.
Syntax
fetch(url, { cache, next: { revalidate, tags } }) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
cache | 'force-cache' | 'no-store' | No | Whether to use the Data Cache (in Next 15 the default is `no-store` unless cached explicitly). |
next | { revalidate?: number | false, tags?: string[] } | No | Time-based revalidation and cache tags. |
Returns
Promise<Response> — A standard Response, optionally cached.
Examples
// Cache and revalidate every 60s (ISR for this data)
export default async function Page() {
const res = await fetch('https://api.example.com/posts', {
next: { revalidate: 60, tags: ['posts'] },
})
const posts = await res.json()
return <PostList posts={posts} />
}
// Always fresh, never cached
const res = await fetch('https://api.example.com/me', {
cache: 'no-store',
})
// Explicitly cache indefinitely
const res = await fetch('https://api.example.com/config', {
cache: 'force-cache',
})
Notes
In Next 15 fetch requests are NOT cached by default (the Next 14
default of `force-cache` was removed) — opt in with
`cache: 'force-cache'` or `next.revalidate`. Tag requests with
`next.tags` and invalidate via `revalidateTag()`. Identical fetches
in one render are deduplicated automatically.