From reading this page in the Next JS docs, this is my current understanding of ISR. When contents are updated in an external CMS (or other APIs), the following takes place behind Next JS:
- On the first request, Next JS will serve the cached page that is now outdated from the CMS content; however, this request triggers a rebuild of that page (provided that the revalidation time has passed).
- On the following and subsequent requests, Next JS will now serve the newly generated page which is now up to date.
- It will serve the new cached page until the revalidation time has passed, at which point Next JS will repeat step no. 1.
A potential issue I see is that whoever visits the page for the first time, after the content on CMS had been changed won't see the new content. The second person to visit the same page will see the new content for the first time, but not the first person.
I was wondering if there are any ways to make sure that the first person to visit also sees the latest content? For example, I can think of two possible work arounds, but I'm wondering if there are better solutions.
- When a content is updated for a specific page on the CMS side, manually visit the new or updated page to manually trigger a rebuild of that page (or have this automated so that when CMS saves a change, some serverless function visits the new page to trigger rebuild of the page). This way, when an actual website visitor loads the page, they will see the latest content. Similar discussion I found here but a built-in way to do it without serverless?: #11698 Comment
- Somehow have Next JS inject new props into the page when it finishes rebuilding. This way the first visitor will see the old content for a very short time, and then the content (page props) are swapped.
- (maybe a feature to add in the future), have a helper function from Next to invalidate the cached page and force pre-rendering again (but for per page basis)
Are there recommended solutions to this? Or are the two possible solutions feasible? Thank you in advance for reading my very long question.