Next.js Discord

Discord Forum

fetch in NextJS 15

Unanswered
AlbertC0527 posted this in #help-forum
Open in Discord
Avatar
When I used fetch() in a server component, calling an api like http://www.randomnumberapi.com/api/v1.0/random?min=100&max=1000&count=1
Every time i build then start the app it still gives me the same number.
I read here that the default for fetch is [no cache](http://www.randomnumberapi.com/api/v1.0/random?min=100&max=1000&count=1)

Can someone help me understand this contradiction.

2 Replies

Avatar
Even more confusing, [here](https://nextjs.org/blog/next-15-rc#fetch-requests-are-no-longer-cached-by-default) it says that if no option is provided to fetch, it uses cache:no-store, but if you try out fetch with no option then try fetch with cache:no-store, the former gives you a static page and the later gives you a dynamic page.
Avatar
Longtail tuna
Yes, quite confusing. But I always rely on docs, not some blog posts. And [here](https://nextjs.org/docs/app/api-reference/functions/fetch) you can read that the default is:
auto no cache (default): Next.js fetches the resource from the remote server on every request in development, but will fetch once during next build because the route will be statically prerendered. If Dynamic APIs are detected on the route, Next.js will fetch the resource on every request.