From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Path-based revalidation

Path-based revalidation

Now, let's see another way of revalidating the page. Currently, in our application, we need the Next.js app to revalidate the home page whenever the data is changed, be it adding, editing or deleting of a product. So we made the home page dynamic using the revalidate keyword. However, the actual need to re-render the page arrives when a product is added, edited or removed. Now, when we say revalidate is equal to 0 or is equal to 5, then the page will be revalidated and rendered again on every request or on every request made after 5 seconds respectively. Now until there is no change in data, revalidating is not required, which means revalidating by time is actually not the most optimized way in this case. We want to revalidate on change of data, for which we can use the revalidatePath method. RevalidatePath is used to revalidate a particular page by giving its path on calling the method. It takes two arguments. First is the path that you want to revalidate. Second is the type of…

Contents