PURGE

Caching

Removing cached content from CDN edges before its TTL expires. Can target a single URL, a group of URLs by tag/key, or the entire cache. Essential for deploying content updates quickly.

Updated Mar 9, 2026

Full Explanation

Caching is great until you need to update something. Published a typo? Pushed a bad CSS file? You can wait for the TTL to expire, or you can purge. Purging tells the CDN to delete the cached version immediately so the next request fetches fresh content from origin.

There are different purge strategies. Single URL purge: remove one specific resource. Tag/key purge: remove all objects tagged with a specific key (e.g., purge everything tagged "product-123"). Wildcard purge: remove everything matching a pattern. Full purge: nuke everything.

Tag-based purging (using Surrogate-Key or Cache-Tag headers) is the most powerful approach. You tag responses during origin responses, then purge by tag when content changes. No need to know every URL, just the logical content group. Fastly and Cloudflare both support this.

Examples

# Cloudflare: purge single URL
curl -X POST "https://api.cloudflare.com/client/v4/zones/{zone}/purge_cache" \
  -H "Authorization: Bearer {token}" \
  -d '{"files": ["https://cdn.example.com/style.css"]}'

# Fastly: purge by surrogate key
curl -X POST "https://api.fastly.com/service/{id}/purge/product-123" \
  -H "Fastly-Key: {token}"

# Varnish: PURGE method
$ curl -X PURGE https://cdn.example.com/style.css

# Varnish VCL: ban (regex purge)
ban req.url ~ "^/static/.*\.css$"

# Nginx: proxy_cache_purge
location /purge {
    proxy_cache_purge cache_zone $uri;
}

Video Explanation

Frequently Asked Questions

Removing cached content from CDN edges before its TTL expires. Can target a single URL, a group of URLs by tag/key, or the entire cache. Essential for deploying content updates quickly.

# Cloudflare: purge single URL
curl -X POST "https://api.cloudflare.com/client/v4/zones/{zone}/purge_cache" \
  -H "Authorization: Bearer {token}" \
  -d '{"files": ["https://cdn.example.com/style.css"]}'

# Fastly: purge by surrogate key
curl -X POST "https://api.fastly.com/service/{id}/purge/product-123" \
  -H "Fastly-Key: {token}"

# Varnish: PURGE method
$ curl -X PURGE https://cdn.example.com/style.css

# Varnish VCL: ban (regex purge)
ban req.url ~ "^/static/.*\.css$"

# Nginx: proxy_cache_purge
location /purge {
    proxy_cache_purge cache_zone $uri;
}

Related CDN concepts include:

  • Surrogate Key / Cache Tag — A label attached to cached responses that allows purging all content with that label, regardless …
  • Cache Busting — Technique for forcing browsers and CDNs to fetch a fresh version of a resource by …
  • Cache-Control — The primary HTTP header for controlling caching behavior. Tells browsers, CDNs, and proxies whether to …
  • Stale Content — Cached content whose TTL has expired but is still stored. Can be served during origin …
  • TTL (Time To Live) (TTL) — How long a cached response is considered fresh before it must be revalidated or re-fetched. …