Next.js - Rebuild Only New Pages

Viewed 26

I am trying to build a website where a only 2 pages will be updated and 1 will be created ~daily. In my case, that would imply getting the new page to be created via an API route in a NodeJs backend, and the updated content also would come from an API, but to update the redux state.

All other pages would stay completely the same. The problem is, if I build from next.js, this build time would increment daily and this is not a good option.

Is there a way to build only the differences / force some pages to stay the same?

1 Answers

try the code below. for more check this link: Incremental Static Regeneration

export async function getStaticProps() {
const res = await fetch('https://.../newPost')
const newPost = await res.json()

return {
  props: {
     newPost,
  },
  // Next.js will attempt to re-generate the page:
  // - When a request comes in
  // - At most once every day
 revalidate: 86400, // seconds in a day
 }
}
Related