---
title: "On-Demand ISR"
description: "Instantly update content without redeploying."
url: "https://vercel.com/templates/next.js/on-demand-incremental-static-regeneration"
links:
  repository: "https://github.com/vercel/on-demand-isr"
  demo: "https://on-demand-isr.vercel.app/"
  deploy: "https://vercel.com/new/clone?demo-title=On-Demand+ISR&demo-description=Instantly+update+content+without+redeploying.&demo-url=https%3A%2F%2Fon-demand-isr.vercel.app%2F&demo-image=%2F%2Fimages.ctfassets.net%2Fe5382hct74si%2F5TY3yVmUYix5mHgfUjhSD0%2Fe505b67dc1ff11c76e1cff9f680ad74f%2FCleanShot_2022-04-13_at_17.12.05_2x.png&project-name=On-Demand+ISR&repository-name=on-demand-incremental-static-regeneration&repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fon-demand-isr&from=templates&skippable-integrations=1"
---

# On-Demand ISR

Instantly update content without redeploying.

### Overview

If you set a `revalidate` time of `60`, all visitors will see the same generated version of your site for one minute. The only way to invalidate the cache is from someone visiting that page after the minute has passed.

Starting with `v12.1.0`, Next.js supports on-demand Incremental Static Regeneration to manually purge the Next.js cache for a specific page. This makes it easier to update your site when:

- Content from your headless CMS is created or updated
- Ecommerce metadata changes (price, description, category, reviews, etc.)

Inside `getStaticProps`, you do not need to specify `revalidate` to use on-demand revalidation. If `revalidate` is omitted, Next.js will use the default value of `false` (no revalidation) and only revalidate the page on-demand when `unstable_revalidate` is called.

### Usage

First, create a secret token only known by your Next.js app. This secret will be used to prevent unauthorized access to the revalidation API Route. You can access the route (either manually or with a webhook) with the following URL structure:

```bash
https://<your-site.com>/api/revalidate?secret=<token>
```

Next, add the secret as an [Environment Variable](https://github.com/vercel/on-demand-isr/tree/main/docs/basic-features/environment-variables.md) to your application. Finally, create the revalidation API Route:

```jsx
// pages/api/revalidate.js

export default async function handler(req, res) {
  // Check for secret to confirm this is a valid request
  if (req.query.secret !== process.env.MY_SECRET_TOKEN) {
    return res.status(401).json({ message: 'Invalid token' })
  }

  try {
    await res.unstable_revalidate('/path-to-revalidate')
    return res.json({ revalidated: true })
  } catch (err) {
    // If there was an error, Next.js will continue
    // to show the last successfully generated page
    return res.status(500).send('Error revalidating')
  }
}
```

[View our demo](https://on-demand-isr.vercel.app) to see on-demand revalidation in action and provide feedback.

### Testing on-demand ISR during development

When running locally with `next dev`, `getStaticProps` is invoked on every request. To verify your on-demand ISR configuration is correct, you will need to create a [production build](https://github.com/vercel/on-demand-isr/tree/main/docs/api-reference/cli.md#build) and start the [production server](https://github.com/vercel/on-demand-isr/tree/main/docs/api-reference/cli.md#production):

```bash
$ next build
$ next start
```

Then, you are able to validate static pages are successfully revalidated.

## Related Templates

### [Nextra: Docs Starter Kit](https://vercel.com/templates/next.js/documentation-starter-kit)

Simple, powerful and flexible markdown-powered docs site. Built with Next.js.

### [Portfolio Starter Kit](https://vercel.com/templates/next.js/portfolio-starter-kit)

Easily create a portfolio with Next.js and Markdown.

### [Next.js Boilerplate](https://vercel.com/templates/next.js/nextjs-boilerplate)

Get started with Next.js and React in seconds.

---

## Additional documentation

The [Vercel Knowledge Base](https://vercel.com/kb) contains guides and answers to common questions about Vercel, including deployment, framework configuration, domains, caching, and troubleshooting.
