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.

RQ: Path-based revalidation

RQ: Path-based revalidation

How can we revalidate the page or path when the data is updated? So to revalidate the path on change of the data, 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 revalidation that is either it can be page or it can be layout. By default it is set to page which means that the particular page will only be revalidated. So if I write slash home then only the slash home page will be revalidated. If I select layout, then all the child routes of the given route will also be revalidated. Next question, is the path-based revalidation more efficient than time-based cache control? The answer is yes. If there is no change in data, then revalidating is not required, which means revalidating by time is actually not the most optimized way in this case. So if we use path based revalidation then the page will revalidate only…

Contents