Next.js Discord

Discord Forum

force-dynamic vs revalidate

Unanswered
NuclearMonkey posted this in #help-forum
Open in Discord
I'm confused between the difference, since they are almost the same, when are they different?

17 Replies

@NuclearMonkey I'm confused between the difference, since they are almost the same, when are they different?
force-dynamic - the page will always render on the server
revalidate - the page will render the page on server and cache the data for the amount you set
what if the revalidate is 0
if revalidate is 0, are they the same
revalidate = 0 === force-dynamic
are there more nuance difference?
between using one over the other if revalidate is 0 vs force-dynamic
@NuclearMonkey are there more nuance difference?
yes, revalidate = 0 means you can still override the dynamicity of your in-page fetch/unstable_cache with options, while force-dynamic will force everything to be dynamic and your local fetch options no longer get respected

that's why i always use revalidate = 0 now
@Ray I was just testing it and I can see the fetch-cache still cache the data from `fetch` with `force-dynamic` on the page👀
hmm that's strange. per the documentation
0: Ensure a layout or page is always dynamically rendered even if no dynamic functions or uncached data fetches are discovered. This option changes the default of fetch requests that do not set a cache option to 'no-store' but leaves fetch requests that opt into 'force-cache' or use a positive revalidate as is.
so that's probably a bug
that "leaves fetch requests that opt into 'force-cache' or use a positive revalidate as is" part is what differentiates force-dynamic from revalidate=0
another question, https://github.com/vercel/next.js/issues/43307#issuecomment-1717123136. When was the nextjs version that enabled prefetch on dev mode?
@joulev that "leaves fetch requests that opt into 'force-cache' or use a positive revalidate as is" part is what differentiates force-dynamic from revalidate=0
i was asking this question because some code in tutorials, I cant replicate
because only in prod mode is prefetch
that's why I was confused.hahahha
@NuclearMonkey because only in prod mode is prefetch
prefetch !== caching