Enhancing Website Performance with Cached Screenshots

Why Caching Screenshots is Important

Caching website screenshots is a powerful technique to boost performance and minimize API usage. By storing screenshots of your web pages, you avoid generating the same screenshots repeatedly, which can be resource-intensive and slow down your operations.

Implementing screenshot caching not only speeds up the process but also reduces the load on your servers and network. This is particularly valuable for monitoring websites, quality assurance, and analytics where frequent screenshots of unchanged content can be avoided.

How to Enable Screenshot Caching

To enable caching for your website screenshots, use the ttl (Time To Live) URL parameter to specify the duration in seconds for which the screenshot should be cached.

For example, setting &ttl=30 will cache the screenshot for 30 seconds. This means if you request the same screenshot within this period, you'll receive the cached version instead of generating a new one.

Example of a Cached Screenshot Request

To request a screenshot of google.com and cache it for one day (86400 seconds), use the following request:

// Example request for a daily cached screenshot https://api.addscreenshots.com/screenshots
?apikey=
YOUR_API_KEY
&ttl=86400
&url=google.com

Your API key can be found on the API Keys page. Need an API Key? Sign up to get started.
For internal applications, replace YOUR_API_KEY with your own unique API Key.
For public facing websites or hotlinks, generate a signed URL.

Common Cache Durations

Here are some typical Time To Live (TTL) values for caching durations:

Cache DurationURL Parameter
10 minutes&ttl=600
1 hour&ttl=3600
1 day&ttl=86400
1 week&ttl=604800
1 month&ttl=2592000

Default Cache Settings

By default, screenshots are not cached. This ensures that each request returns the most current version of the page, which is ideal for dynamic or frequently updated content. However, for static or less frequently changing pages, enabling caching can significantly enhance performance and reduce API consumption.

Using Your Own CDN for Caching

Yes, you can use your own Content Delivery Network (CDN) to cache screenshots. Storing screenshots on platforms like Azure Blob Storage or an AWS S3 Bucket and pointing your CDN to these storage accounts gives you full control over caching and delivery.

How Caching Works

Here's a quick overview of the caching process:

  1. Receive the screenshot request with URL and options (e.g., quality, format, viewport)
  2. Check if a cached screenshot exists for the requested URL and TTL
  3. Return the cached screenshot if available and valid
  4. If no valid cached screenshot is found, capture a new screenshot
  5. Store the new screenshot in the cache
  6. Return the newly captured screenshot

Where Are Cached Screenshots Stored?

Cached screenshots are stored using Cloudflare, ensuring efficient delivery and access.

Limitations of Screenshot Caching

Be aware of the following limitations:

  1. Only GET requests are supported for caching (POST requests are not cached)
  2. Caching is available only for active accounts

Benefits of Caching

Implementing caching for website screenshots offers significant benefits, including improved performance, reduced API usage, and lower operational costs. By avoiding redundant screenshot generation, you can streamline your processes and ensure faster access to static content.