What are the tradeoffs between using revalidatePath and revalidateTag for a large application with many interconnected pages?
Short answer
revalidatePath is simple and direct but requires you to know every specific path affected by a change, which can be error prone in complex apps, while revalidateTag is more flexible and scalable since you tag data once and can revalidate everything using that data across the…
Advertisement
AModel answer
revalidatePath is simple and direct but requires you to know every specific path affected by a change, which can be error prone in complex apps, while revalidateTag is more flexible and scalable since you tag data once and can revalidate everything using that data across the entire site with a single call, though it requires careful tag naming and organization.
// revalidatePath requires knowing every affected path
revalidatePath('/blog');
revalidatePath('/blog/featured');
// revalidateTag revalidates everywhere the tag is used
revalidateTag('blog-posts');Real-world example
A large media company switches from manually listing dozens of paths to revalidate after every content change, to a well organized tagging system that automatically refreshes every affected page with far less code.
Likely follow-ups
- How do you organize a consistent tagging strategy across a large codebase?
- Is there a performance difference between the two approaches at scale?
Related topics