Tutorial · cloudflare · Published 2026-08-15 · 3 min read
How to purge Cloudflare cache
Purge Cloudflare cache by URL, prefix or hostname, use the API, and understand that purging invalidates and re-fetches rather than deletes.
What a purge does
Purging Cloudflare cache deletes one or more cached files from the edge. The next request for that item travels to the origin, re-fetches the current file, and stores the fresh copy. Purge is invalidate-then-re-fetch, not a "reset cache" that pre-builds anything.
Know the difference first: purging the CDN cache (Cloudflare) does not touch the browser cache. A visitor who already got the old asset keeps the old copy until their browser cache expires, so pair a purge with a cache-busting URL or an edge cache rule that forces a TTL.
What you can purge
| Purge scope | Removes | Best for |
| Single URL | One exact URL or file | A changed asset, a corrected page |
| Prefix | Everything under a path | A directory, a blog category, an image dir |
| Hostname | All cached content for one host | Rebuilds, template changes, CSS/JS rollouts |
| Everything | Whole zone | Last resort, site rebuild |
Purge in the dashboard
- Open Caching > Configuration (older UI: Caching > Purge Cache).
- Choose the granularity. For a single file use Custom purge and type the exact URL:
https://www.example.com/assets/app.css
https://www.example.com/updated-page/
- Click Purge. The edge marks the entries invalid, and the next request re-fetches.
For a prefix purge, type the URL prefix. The prefix must start with a valid scheme, for example https://www.example.com/wp-content/. Cloudflare invalidates everything cached under that prefix across the matching host.
Purge with the API
The zone-level endpoint expects a JSON body:
curl -X POST "https://api.cloudflare.com/client/v4/zones/{zone_id}/purge_cache" \
-H "Authorization: Bearer $CF_TOKEN" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}'
| Body | Scope |
| {"purge_everything":true} | Whole zone cache |
| {"files":["https://example.com/style.css"]} | Exact list of file URLs |
| {"prefixes":["https://example.com/wp-"]} | Path prefix purge |
Your API token needs the Cache Purge permission for the zone. Purging by prefix or by hostname works on those scopes only; to clear a whole set you still use the files, prefixes, or purge_everything forms above. Note that purging marks entries invalid, it does not delete files from your origin, so a request for the purged URL simply re-fetches from the origin.
Purge versus automatic cache busting
Purge is the manual control, not the ongoing habit. For a production site, prefer:
- Cache-busting asset names (
style.v2.css): the URL changes, so old cache entries simply go stale on their own. - Edge cache TTL rules that lower TTL for files you change often.
- Origin response headers (
Cache-Control) that tell the edge what is cacheable in the first place.
Whether a purge changes anything still depends on the file being cacheable. A dynamic page that renders per request is not cached unless a cache rule says otherwise, so purging a page that was never cached changes nothing for that URL.
Prevention
- Put the purge API call in your deploy script, so deploy and purge travel together.
- Keep the purge token scoped and named (not the global key) so a leaked token can be rotated without touching everything.