Help How to disable build-time pre-rendering but still enable cachine after the first request?
My build time environment for my front-end doesn't have access to my back-end to pre-render. Is there a way I can disable build-time pre-rendering but still have a cache with time-based invalidation policy of 10 minutes or so? Anyway, the cache becomes invalid by the time the app is ready to be deployed anyway so that's another reason for disabling build-time pre-rendering.
Does this work?
export const dynamic = "force-dynamic";
const revalidate = 600;
[EDIT] The above does not work. But What does work is setting dynamic to "force-dynamic" and then forcing the caching at the level of the fetch request like this:
await fetch(url, { next: { revalidate: 600 }, cache: "force-cache"}
It's very unfortunate for two reasons:
- Creates a lot of boiler plate.
- I was using `axios` and now I need to use the raw fetch librayr.
1
u/exeSteam 2h ago
There's an experimental feature that solves this issue. You can build the app with
next build --experimental-build-mode compile
Then to run the app when the API is available
next build --experimental-build-mode generate
next start
2
u/Pawn1990 23h ago
Do export const dynamic = “force-static” or remove the dynamic line completely.
Then add an export const generateStaticParams function that returns an empty array.
This should enable ISR caching but not render them on build, only after first hit