Automate Static Rebuilds in Next.js 15 Using Vercel Cron Jobs

Learn how to use Vercel cron jobs with Next.js 15 to automatically rebuild your static site on a daily schedule. Keep your content, sitemaps, and RSS feeds always up to date—without manual deployment.

FKJune 18, 2025

Imagine you just wrote a new blog post and scheduled it to publish next week at 8 AM. But will your sitemap update? Will your category pages refresh? Will everything just work when the article goes live? If you plan content ahead, you might have faced this exact problem.

The solution is to automate daily builds for your Next.js site using Vercel cron jobs so your static content stays in sync. Using Vercel cron jobs, you can schedule your site to rebuild every day (for example, at 8 AM) without manual work. This ensures your static pages, sitemaps, and RSS feeds are always up to date with your content schedule. In this tutorial, I’ll show how to use Vercel cron jobs and Next.js (even in Next.js 15) to trigger a daily rebuild of your site. No more stale content, and everything stays fresh and current!

Why Automate Site Rebuilds with Vercel Cron Jobs

For static or hybrid Next.js sites (using getStaticProps), using Vercel cron jobs (often called Next.js cron jobs) to schedule builds is an easy way to keep content current without requiring server-side rendering. Using Vercel cron jobs, your site will rebuild at regular intervals, making sure everything stays up to date. This is useful when you:

  • Plan to publish posts or content at a future date.
  • Need sitemaps, category pages, or RSS feeds to refresh automatically.
  • Pull data from external APIs that change periodically.
  • Want to make sure your static pages stay fresh.
  • Have pages with time-sensitive data that need regular updates.
  • Prefer to keep your site fast and static while updating content on a schedule.

Each day, the site rebuild will fetch new content and rebuild pages, so everything stays in sync with your schedule. This approach works well with Next.js 15 and earlier versions and avoids the complexity of real-time server rendering.

What We’re Building

In this tutorial, I'll set up a daily rebuild for our Vercel-hosted Next.js site. This means the site will automatically rebuild every day at 8 AM (or whatever time you choose). To do this, we’ll use a few pieces:

  • Vercel Cron Jobs: Vercel’s built-in scheduling feature to run a task daily.
  • Next.js API endpoint: A custom endpoint in your Next.js app (like an API route) that can trigger the rebuild.
  • Vercel Deploy Hook: A Vercel webhook URL that actually starts the site rebuild when called.

With these in place, your site will rebuild itself on schedule, keeping static pages, sitemaps, and feeds up to date.

Set Up the Vercel Cron Job Configuration

Create a vercel.json file in the root of your project. This file tells Vercel about your cron job schedule. Add the following:

JSONvercel.json
{  "crons": [      {      "path": "/api/rebuild",      "schedule": "0 8 * * *"      }  ]}

In this example, the schedule "0 8 * * *" uses standard cron syntax:

  • 0 (minute) means 0 minutes.
  • 8 (hour) means 8 AM.
  • The first * (day of month) means every day.
  • The second * (month) means every month.
  • The third * (day of week) means every day of the week.

This setup tells Vercel to send a request to /api/rebuild every day at 8:00. Important: Vercel’s free tier only allows one cron job, so plan your schedule carefully.

Create the Rebuild API Endpoint

Now we need an API endpoint in our Next.js app that will trigger the rebuild. If you’re using the Next.js App Router (Next.js 13 or 15), create a file at src/app/api/rebuild/route.ts. In older versions (pages router), this would be pages/api/rebuild.js or .ts. Add the following code to route.ts:

TypeScriptroute.ts
import { NextRequest, NextResponse } from 'next/server'  export async function GET(request: NextRequest) {  try {    // Trigger a rebuild by making a request to Vercel's build hook    const buildHookUrl = process.env.VERCEL_BUILD_HOOK_URL;      if (!buildHookUrl) {      return NextResponse.json(        { error: 'Build hook URL not configured' },        { status: 500 }      );    }      const response = await fetch(buildHookUrl, {      method: 'POST',    });      if (!response.ok) {      throw new Error(`Build hook failed: ${response.status}`);    }      return NextResponse.json({       success: true,       message: 'Build triggered successfully',      timestamp: new Date().toISOString()    });} catch (error) {   console.error('Rebuild cron job failed:', error);      return NextResponse.json(     { error: 'Failed to trigger rebuild' },     { status: 500 }   );}

This code uses NextResponse to return JSON. It reads the webhook URL from process.env.VERCEL_BUILD_HOOK_URL. If the URL isn’t set, it responds with an error. Otherwise it sends a POST request to that URL. If the request is OK, it returns a success message; if not, it throws an error and returns a failure message. The try/catch ensures any issues are caught and logged.

Create a Vercel Deploy Hook

Next, set up a deploy hook in your Vercel project. This is a special webhook URL that will actually start the build. On Vercel’s dashboard:

  1. Go to your project and navigate to SettingsGitDeploy Hooks.
  2. Click Create Hook.
  3. Give the hook a name like "Daily Rebuild".
  4. Choose the branch you want to rebuild (usually main or master).
  5. Click Create to save the hook.
  6. Copy the generated webhook URL.

You will use this webhook URL in the next step to trigger the rebuild from your API endpoint.

Add the Webhook URL as an Environment Variable

Now store the webhook URL in an environment variable so our API endpoint can use it. In your Vercel dashboard:

  1. Go to Settings → Environment Variables.
  2. Add a new variable:
    • Name: VERCEL_BUILD_HOOK_URL
    • Value: (paste the webhook URL you copied from Step 3)
    • Environment: Select Production (and Preview if needed for testing).

By doing this, the rebuild endpoint can read the VERCEL_BUILD_HOOK_URL from the environment when it runs on Vercel.

Deploy and Test

Commit and push your changes to Vercel to apply the new configuration. For example:

GNU Bash>.sh
git add vercel.json src/app/api/rebuild/route.tsgit commit -m "Add daily rebuild cron job"git push origin main

This will deploy your site with the new cron job setup. To test it, visit your rebuild endpoint in the browser or via curl. For example:

GNU Bash>.sh
curl https://yoursite.vercel.app/api/rebuild

You should see a JSON response indicating success, and a new deployment should appear in your Vercel dashboard. This means the rebuild was triggered correctly.

Optional: Trigger Rebuilds Manually

You can also trigger the rebuild endpoint from anywhere in your app or from a CMS webhook. For example, you could call the /api/rebuild endpoint in response to some event (like a content update). Here’s a sample function you might use:

JavaScripttrigger-rebuild.js
async function triggerRebuild() { try {    const response = await fetch('/api/rebuild');    const result = await response.json();    if (result.success) {      console.log('Rebuild triggered successfully');    } } catch (error) {    console.error('Failed to trigger rebuild:', error); }}

This function sends a request to /api/rebuild, which in turn calls the Vercel hook. If result.success is true, the rebuild was triggered.

Monitoring and Debugging

After the cron job is set up, you should check that it’s working as expected. In the Vercel dashboard:

  • Check the Functions tab for logs from your API endpoint.
  • Check the Deployments tab to see if new builds appear each day.

You can also add console.log statements to your endpoint code for debugging. For example:

TypeScriptroute.ts
export async function GET(request: NextRequest) {console.log('Cron job triggered at:', new Date().toISOString());// ... rest of your codeconsole.log('Build hook response status:', response.status);return NextResponse.json({success: true,message: 'Build triggered successfully',timestamp: new Date().toISOString(),buildHookStatus: response.status});} 

Cron Schedule Examples

You can customize the cron schedules in vercel.json. For example, you might add entries like:

JSONvercel.json
{"crons": [  {    "path": "/api/rebuild",    "schedule": "0 8 * * *"     // Daily at 8 AM  },  {    "path": "/api/rebuild",    "schedule": "0 */6 * * *"   // Every 6 hours  },  {    "path": "/api/rebuild",    "schedule": "0 0 * * 1"     // Weekly on Monday at midnight  },  {    "path": "/api/rebuild",    "schedule": "0 2 1 * *"     // Monthly on the 1st at 2 AM  }]}

Pros and Cons

Pros:

  • Keeps static content up to date automatically.
  • Maintains excellent performance because pages stay static/cached.
  • Easy to set up and maintain.
  • Works well when pulling in external data sources.
  • Builds are predictable in timing and resource use.

Cons:

  • Updates are not immediate (they only happen on the schedule).
  • Every rebuild uses your Vercel build minutes.
  • On Vercel’s free tier, you’re limited to one cron job.
  • You need to set up webhooks and environment variables.

Using Vercel cron jobs for daily rebuilds is a powerful way to keep your Next.js site fresh without losing performance. It’s especially handy for blogs, portfolios, or any static site that pulls from external data sources. With the setup above (cron jobs + API endpoint + deploy hook), your site will automatically rebuild on schedule.

This approach is reliable and low-maintenance: once it’s set up, your site stays up to date without manual work. Give it a try to automate your builds and keep your content in sync on any Next.js (including Next.js 15) app using Vercel cron jobs.

Nextjs15
CronJobs
Vercel