Caching strategies for screenshot APIs
Choose the right cache TTL, avoid stale previews and keep your screenshot costs predictable.
The ScreenshotDude team · · 2 min read
Rendering a page in a real browser takes around a second or more. If you show the same screenshot to thousands of users — link previews, directory thumbnails, social cards — you don't want to render it every time. That's what caching is for.
Built-in edge caching
Add cache=true and the response is stored. Identical requests within the TTL are served from cache, instantly:
curl -G "https://api.screenshotdude.com/v1/capture" \
--data-urlencode "url=https://example.com" \
-d cache=true -d cache_ttl=86400 \
-H "x-api-key: $SCREENSHOTDUDE_API_KEY" -I
# x-cache: MISS (first request)
# x-cache: HIT (subsequent requests)cache_ttlis in seconds. The default is one day (86,400) and the maximum is 30 days (2,592,000).- The cache key includes all rendering parameters, so
format=pngandformat=webpare cached separately. - Check the
x-cacheresponse header to see whether you got aHITor aMISS.
Picking a TTL
| Content | Suggested TTL |
|---|---|
| Marketing pages, homepages | 1–7 days |
| Documentation, blog posts | 7–30 days |
| News front pages, dashboards | 15 minutes – 1 hour |
| Prices, stock, live data | Don't cache, or keep it very short |
Layer your own cache in front
For high-traffic previews, put your CDN or object storage in front of the API:
- Upload the capture to your own bucket with
s3_url=true— you get JSON with the file URL. - Store the URL in your database next to the source URL and a timestamp.
- Serve the image from your CDN. Refresh it in the background when it's older than your TTL.
This pattern ("stale-while-revalidate") keeps pages fast even when a refresh is in progress.
Busting the cache
Need a fresh capture right now? Send the request without cache=true — it always renders a new screenshot. You can also vary a harmless parameter, but explicit is better.
Don't forget the costs
Cache hits are still counted as requests, but they return instantly and never consume rendering time, so they make your latency — and your infrastructure — predictable. Combine caching with the pricing calculator to size your plan.
More details in the caching guide.