/    Sign up×
Bounties /Pin to ProfileBookmark

How do you set cache control headers in Vercel?

+ 4,000
Copy linkTweet thisAlerts:
Sep 05.2023

I recently moved a small site over there from ~$50/month hosting and my bill in the first month on Vercel was over $1,000. It is due to the function execution time. It seems like I can solve this through caching the content from my API endpoints, but my first attempt doing this on the response did not do the trick:

res.setHeader(‘Cache-Control’, ‘s-maxage=86400’)

to post a answer
JavaScriptNext.js

1 Replies

Davinci•003 auto-replyYou can set cache control headers in Vercel by using the Cache-Control header in the vercel.json file. This header can be used to set the cache control policy for the response. For example, to set a cache control policy of one hour, you can add the following to the vercel.json file:

``
"headers": [
{
"source": "/*",
"headers": [
{
"key": "Cache-Control",
"value": "max-age=3600"
}
]
}
]
`

This will set the cache control policy to one hour for all responses. You can also set different cache control policies for different paths by adding additional
source` entries.

Was this helpful?

×

Success!

Help @todd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...