- How to Use Vercel Cron Jobs to Keep Static Content in Sync
How to Use Vercel Cron Jobs to Keep Static Content in Sync
Automatically trigger daily site rebuilds to ensure your static pages, sitemaps, and RSS feeds stay up to date with scheduled content.

Picture this: you've just finished writing a brilliant blog post, scheduled it to publish next Tuesday at 8 AM, and now you're wondering if your sitemap will update, your category pages will refresh, and everything will just work when that article goes live. If you're like me and schedule content in advance, you've probably run into this exact scenario.
The solution? Automated daily rebuilds that ensure your static site stays perfectly synchronized with your content schedule. No more worrying about stale sitemaps or missing category updates. This guide walks through setting up a rock-solid daily build system using Vercel's cron jobs and webhooks that handles all the heavy lifting for you.
Why This Matters
For static or hybrid static sites, especially those using Next.js' getStaticProps
, scheduled rebuilds are a clean way to stay up to date without needing real-time server-side rendering. This approach is perfect when you:
- Schedule blog posts or content to publish in the future
- Need sitemaps, category pages, and RSS feeds to update automatically
- Pull content from external APIs that update periodically
- Want to ensure your static content stays fresh
- Need to regenerate pages with time-sensitive data
- Want to maintain optimal performance while keeping content current
What We'll Build
We'll set up a system that automatically rebuilds your Vercel-hosted site every day at 8 AM using:
- Vercel's built-in cron jobs
- A custom API endpoint to trigger rebuilds
- Vercel's deploy hooks for seamless integration
Step 1: Create the Vercel Configuration
First, create a vercel.json
file in your project root to configure the cron job:
{
"crons": [
{
"path": "/api/rebuild",
"schedule": "0 8 * * *"
}
]
}
The schedule "0 8 * * *"
follows the standard cron format:
0
- minute (0)8
- hour (8 AM)*
- day of month (every day)*
- month (every month)*
- day of week (every day of the week)
Important: Vercel's free tier supports only one cron job, so choose your schedule wisely.
Step 2: Create the Rebuild API Endpoint
Next, create the API endpoint that will handle the rebuild trigger. Create a new file at src/app/api/rebuild/route.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 }
);
}
}
Step 3: Set Up Vercel Deploy Hook
Now you need to create a deploy hook in your Vercel dashboard:
- Go to your project dashboard on Vercel
- Navigate to Settings → Git → Deploy Hooks
- Click Create Hook
- Give it a name (e.g., "Daily Rebuild")
- Select the branch you want to rebuild (usually
main
ormaster
) - Copy the generated webhook URL
Step 4: Configure Environment Variable
Add the webhook URL to your environment variables:
- In your Vercel project dashboard, go to Settings → Environment Variables
- Add a new variable:
- Name:
VERCEL_BUILD_HOOK_URL
- Value: The webhook URL you copied from Step 3
- Environment: Production (and Preview if needed)
- Name:
Step 5: Deploy and Test
Deploy your changes to Vercel:
git add vercel.json src/app/api/rebuild/route.ts
git commit -m "Add daily rebuild cron job"
git push origin main
To test your setup manually, you can visit your API endpoint:
https://yoursite.vercel.app/api/rebuild
You should see a JSON response indicating success, and a new deployment should appear in your Vercel dashboard.
Advanced: On-Demand Rebuilds
You can also trigger rebuilds programmatically whenever needed. For example, when content is updated in your CMS:
// Trigger rebuild from anywhere in your app
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 is particularly useful for:
- CMS webhook integrations
- Content update notifications
- Manual refresh buttons in admin interfaces
Monitoring and Debugging
To monitor your cron jobs:
- Check the Functions tab in your Vercel dashboard for execution logs
- Monitor the Deployments tab to see if rebuilds are triggering as expected
- Add logging to your API endpoint for better debugging
You can enhance the API endpoint with additional logging:
export async function GET(request: NextRequest) {
console.log('Cron job triggered at:', new Date().toISOString());
// ... rest of your code
console.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
Here are some common cron schedules you might want to use:
{
"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 Tradeoffs
Pros:
- Keeps static content fresh without manual intervention
- Excellent performance (sites remain static/cached)
- Simple to set up and maintain
- Works great with external data sources
- Predictable build times and resource usage
Tradeoffs:
- Content updates aren't immediate (depending on schedule)
- Uses build minutes on every scheduled run
- Limited to one cron job on Vercel's free tier
- Requires webhook setup and environment configuration
When to use this approach:
- Your content updates daily or less frequently
- Performance is more important than real-time updates
- You're pulling from external APIs that update periodically
- You want predictable, scheduled rebuilds
Alternatives to consider:
- Incremental Static Regeneration (ISR) for more responsive updates
- Server-side rendering for real-time data requirements
- Manual webhook triggers from your CMS or external services
Conclusion
Setting up automated daily builds with Vercel cron jobs is a powerful way to keep your static site fresh while maintaining excellent performance. This approach works particularly well for blogs, portfolios, and marketing sites that pull content from external sources.
The combination of Vercel's cron jobs and deploy hooks creates a reliable, maintenance-free system that ensures your site stays current without sacrificing the benefits of static generation.
Thanks, Matija