Next.js Discord

Discord Forum

Stale-while-revalidate (swr) with the App Router?

Unanswered
Least Storm-Petrel posted this in #help-forum
Open in Discord
Least Storm-PetrelOP
Hi šŸ‘‹

I've been wondering for a while but never asked:
How can I implement a stale-while-revalidate pattern (like ISR) for pages in the app router?

Meaning, I want to serve static, cached versions of my dynamic page, revalidate it in the background, and have it replaced by the new version if the revalidation is successful.

Is this even possible with the app router?

4 Replies

Least Storm-PetrelOP
Thanks! I didn't see that.
I haven't tried it out yet. But I seem to rember it not working (at least when Next.js 14 was new) when I invalidated a specific tag (i.e. fetch request). Then, all paths immediately switched to SSR on the next request instead of serving a stale version while doing the revalidation in the background.
Is this still the case? Or rather, will it actually do the revalidation always in the background?
American black bear
I am pretty sure it happens in the background but could not find the docs to reference it.
Perhaps someone else sees this and can give you a definitive answer.