Medium
You are developing a blog using Next.js with the Page Router technology and wish to leverage Incremental Static Regeneration (ISR) for your blog posts. Each article is statically generated at the time of the build, but you want them to update periodically after their initial publication to ensure fast loading speeds and fresh data. Here is a code snippet from the article page :
// pages/posts/[postId].js
export async function getStaticProps({ params }) {
const postData = await getPostData(params.postId);
return {
props: {
postData,
},
revalidate: 10 // time in seconds
};
}
export async function getStaticPaths() {
const paths = getAllPostIds();
return {
paths,
fallback: 'blocking'
};
}
// ...
Author: AnasStatus: PublishedQuestion passed 468 times
Edit
4
Community EvaluationsNo one has reviewed this question yet, be the first!
1
Where to place static files in a Next.js project.1
Fetch the product details from the server on every request and cache it.5
What is the path to the about page in Next.js?2
What are the benefits of using dynamic imports in Next.js?3
Create a NextJS page with a navbar and a footer2
How to manipulate HTTP response headers within a `getServerSideProps` function in Next.js7
Load blog post data at build time for a static render.