Next.js Discord

Discord Forum

Stale while revalidate ssr

Answered
Irish Terrier posted this in #help-forum
Open in Discord
Irish TerrierOP
With the new app router, is there a way to dynamically render a page (or request) but revalidate it after a certain amount of time?

So I have a page that is not prerendered at build time, and the single request I made is being cached for 50000ms and then revalidated.

Basically the same as the old getServerSideProps - stale while revalidare strategy

I've tried
export const revalidate = 50000;
export const dynamic = "force-dynamic";

but it seems is not working properly

Thanks!
Answered by B33fb0n3
yea, that should work as well. You can use searchParams for that to add filter and sortings and ...
View full answer

11 Replies

@Irish Terrier solved?
Irish TerrierOP
@B33fb0n3 Hi! Sorry if I didn't answered yet but I didn't have the chance of trying it yet (I'm working on another project right now), probabily I'll be able to try it this afternoon; I'll let you know and thanks! 🙂
yes it should only revalidate every 50 seconds. Keep the "stale-while-revalidate" in mind
Irish TerrierOP
Yes sorry I was editing my answer
But I would like to do it in a dynamic way, so with no static generation, pretty much like we did with the old getServerSideProps
Probabily the solution would be
export const revalidate = 10;
export const dynamic = "force-static";
The context is that I would like to implement a search page with the possibility of filtering through query params, but I would like to return an instant response for a particular research and in the background revalidate the result
Answer
Irish TerrierOP
Thanks a lot! 🙂
happy to help