Next.js
/Advanced
revalidateTag()
Definition
A utility function that purges cached data across multiple different URLs simultaneously based on a custom string label (tag).
Explain Like I'm New
If you update a Product's price, that price might be displayed on the `/home` page, the `/shop` page, and the `/product/123` page. Calling `revalidatePath` three times is annoying. Instead, you tag all those fetches with `'pricing'`. When the price changes, you just call `revalidateTag('pricing')` and it updates the price everywhere instantly.
Real World Example
A headless CMS webhook. When an editor publishes an article, the CMS pings your API. Your API runs `revalidateTag('articles')`, instantly updating every page on your site that displays articles.
Common Use Cases
- •Complex cache architectures
- •Global data updates
- •CMS Webhooks
Interactive Example
Loading Code Playground...
Interview Questions
basic
- Where do you assign a tag to a specific fetch request?
intermediate
- What is the primary advantage of `revalidateTag` over `revalidatePath`?