How to Cache OG Images
Caching OG images means serving a previously-generated social preview from a CDN instead of re-rendering it on every share. FastOG caches identical images at the edge for a year — the same URL returns the cached PNG in 0 credits and at roughly zero latency, so most of a site's OG traffic never touches the renderer.
Why caching matters
A social share triggers a fetch by the platform's crawler. If every share re-rendered, you would burn credits and latency on identical content. Aggressive caching — keyed on the image's content — turns "every share costs 1 render" into "the first share costs 1 render, every other share is free."
The content-keyed model that makes it work
FastOG uses content-signed URLs: the URL is a pure function of the parameters. Identical title + template → identical URL. That means:
- The CDN caches on the URL.
- Same content shared 10,000 times → one render, one credit, 9,999 cache hits.
- Change the content → different URL → one new render.
GET /api/v1/og?title=Hello&template=default&key=...&s=... → render (1 credit), then
GET /api/v1/og?title=Hello&template=default&key=...&s=... → cached (0 credits, instant)
GET /api/v1/og?title=Changed&template=default&key=...&s=... → render (1 credit)
FastOG's caching headers
FastOG returns Cache-Control: public, max-age=31536000, immutable (one year) for rendered images, and Cloudflare caches the result. Subsequent fetches return cf-cache-status: HIT.
Caching your own og:image (self-hosted)
If you store images yourself instead of using FastOG's cache, apply the same rules:
| Step | Detail |
|---|---|
| Cache key = content hash | Store by a hash of the data, not a mutable filename |
| Long TTL | max-age=31536000, immutable for stable content |
| Versioned URLs | Append a hash/version when content changes |
| CDN in front | Let the CDN absorb repeat fetches |
FAQ
Do repeat shares really cost 0 credits?
Yes. Identical URLs hit the edge cache and never reach the renderer — no credit is consumed.
How long does FastOG cache an image?
One year (immutable). Long after first render, a shared card is served from cache.
What if I want an image to update (e.g. live price)?
Change a parameter (the price) → new URL → new render. Stable content stays cached; dynamic content updates when you want it to.
Related
Try it free — no signup required
Preview and test dynamic OG images in seconds.
Open the Free OG Image Tester