How to use `generateStaticParms` on runtime instead of build-time?
Unanswered
Dutch posted this in #help-forum
DutchOP
How can I not build all static pages in advance, but rather use on-demand during build-time? So the first time a user visits the page it gets cached as a static html. It should not revalidate itself automatically. Only if use
revalidatePath
manually somewhere else.10 Replies
you can do this by returning an empty array inside your generateStaticParams. Like that no route will be build. Then make sure to to enable ISR using this: https://nextjs.org/docs/canary/app/building-your-application/data-fetching/incremental-static-regeneration
And after that it will generate no routes during build time but when a user visits a route, the route will be cached and only revalidated when you call revalidatePath for example
And after that it will generate no routes during build time but when a user visits a route, the route will be cached and only revalidated when you call revalidatePath for example
DutchOP
@B33fb0n3 It doesn't seem to work
I get these Cache headers:
This is my code:
Or is this expected? Am I missing something?
I get these Cache headers:
cache-control: private, no-cache, no-store, max-age=0, must-revalidate
This is my code:
export const dynamicParams = true
// export const revalidate = 60 // also doesn't work
export async function generateStaticParams() {
// do not delete this, otherwise SSR pages won't be cached
return []
}
Or is this expected? Am I missing something?
check the cache header. Check if you get a
HIT
or a MISS
DutchOP
I am not using Vercel, I don't see such kind of header:
@B33fb0n3
where do you host? Does it have a serverside data cache?
DutchOP
I am using coolify with a vps
Serengeti
@Dutch try adding
to the page, i had to do this on my vercel deployed app to get it to be statically generated/cached at request time.
export const dynamic = "force-static";
to the page, i had to do this on my vercel deployed app to get it to be statically generated/cached at request time.
DutchOP
I will try this!
DutchOP
That worked! I also get headers now too