Why my portfolio's images loaded late, and the one setting that fixed it
Payload CMS was quietly sending every image through a serverless function with no caching. Here's how I found it and what I changed.
After I launched this site, something felt off. The text appeared straight away, but the portrait in the hero and the project screenshots arrived a beat later, sometimes two. On a portfolio that's the worst place for a delay: the first thing a visitor sees is an empty frame.
This post is the short version of how I tracked it down. If you run Payload CMS on Vercel with Vercel Blob storage, you may have the same problem.
The setup
The site is a Next.js app with Payload CMS running inside it. Uploaded images go to Vercel Blob, because a serverless host can't keep files on its own disk. The official storage plugin handles that:
vercelBlobStorage({
collections: { media: true },
token: process.env.BLOB_READ_WRITE_TOKEN,
})Uploads worked. Images showed up. Nothing looked broken, which is exactly why it took a while to notice.
What the network tab said
Every image URL on the page looked like this:
/api/media/file/hero-desktop.webpThat's not the Blob URL. It's a Payload API route. So each image request was:
- hitting a serverless function on my site,
- which checked access control (a database query),
- then fetched the file from Blob and streamed it back.
Then I checked the response headers:
Cache-Control: public, max-age=0, must-revalidate
X-Vercel-Cache: MISSmax-age=0 and a cache MISS on every request. Nothing was being cached at the edge. When the function was warm, an image came back in about a quarter of a second. When it was cold, after the site had been quiet for a while, I measured 2–3 seconds per image. For a personal site with modest traffic, "cold" is most visits.
Next.js's image optimiser made it slightly worse, because it fetches the original through the same slow route before resizing it.
Why Payload does this
Proxying files through its own API is a sensible default. It lets Payload enforce access control: a private document can't be downloaded just because someone guessed the URL. But my images are public portfolio screenshots. I was paying for a feature I didn't need.
The fix
The storage plugin has an option for exactly this case:
vercelBlobStorage({
collections: {
media: { disablePayloadAccessControl: true },
documents: { disablePayloadAccessControl: true },
},
token: process.env.BLOB_READ_WRITE_TOKEN,
cacheControlMaxAge: 60 * 60 * 24 * 365,
})With disablePayloadAccessControl, Payload stops proxying and returns the file's real Blob CDN address, something like https://xxxx.public.blob.vercel-storage.com/hero-desktop.webp. The existing database records didn't need a migration; Payload builds the URL when it reads the document.
Because the images now come from a different host, next/image needs to be allowed to load them:
images: {
remotePatterns: [{ protocol: "https", hostname: "*.public.blob.vercel-storage.com" }],
}After deploying, the same image comes back with:
Cache-Control: public, max-age=31536000
X-Vercel-Cache: HITCached for a year, served from the CDN, no function in the way and no cold start.
When not to do this
Only turn off access control for collections that are genuinely public. If you store invoices, private downloads or anything behind a login, keep the proxy for that collection and accept the cost, or put a CDN cache in front of it with care.
The lesson
Nothing was broken, so nothing told me something was wrong. The page "worked". It took actually reading the response headers to see that every visitor was waiting on a database query for a picture of me in a hoodie.
Now, when I hand over a site, checking image headers is on my launch list next to the sitemap and the analytics tag.