How to Purge Cloudflare Cache (Single URL or Entire Site)
In this tutorial, you'll learn about How to Purge Cloudflare Cache (Single URL or Entire Site). We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
The Problem
You updated your website but visitors still see the old version because Cloudflare's edge cache is serving stale content. You need to purge cached files selectively or entirely.
Quick Fix
Step 1: Purge everything from the dashboard
In the Cloudflare Dashboard:
- Select your domain.
- Go to Caching > Configuration.
- Click Purge Everything.
This clears all cached files across every Cloudflare edge node. The next request re-fetches from your origin server.
Step 2: Purge a single URL from the dashboard
- In Caching > Configuration, click Custom Purge.
- Select Single URL.
- Enter the full URL including the scheme:
https://example.com/style.css.
This removes only that specific file from the cache. Other files remain cached.
Step 3: Purge via the API
curl -X POST "https://api.cloudflare.com/client/v4/zones/YOUR_ZONE_ID/purge_cache" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
--data '{"purge_everything": true}'
Replace YOUR_ZONE_ID and YOUR_API_TOKEN with your actual values. Find the zone ID in the dashboard under Overview.
Expected response:
{"success": true, "errors": [], "messages": [], "result": {"id": "..."}}
Step 4: Purge specific files via the API
curl -X POST "https://api.cloudflare.com/client/v4/zones/YOUR_ZONE_ID/purge_cache" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
--data '{"files": ["https://example.com/style.css", "https://example.com/app.js"]}'
Step 5: Purge by hostname, tag, or prefix
curl -X POST "https://api.cloudflare.com/client/v4/zones/YOUR_ZONE_ID/purge_cache" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
--data '{"prefixes": ["https://example.com/blog/"]}'
This purges every URL under /blog/ without affecting the rest of the site.
Step 6: Verify the purge
curl -I https://example.com/style.css | grep -i "cf-cache-status"
Expected:
cf-cache-status: MISS
A MISS status means Cloudflare did not serve a cached copy and fetched from your origin.
Alternative Solutions
Use Cloudflare's API token endpoint without purging everything — set a short Browser Cache TTL during deployments.
Common Errors
API returns "authentication error": The API token must have "Cache Purge" permission. Generate a new token in the Cloudflare dashboard under API Tokens with the correct scope.
Purge not taking effect: Cloudflare edge nodes may take a few seconds to propagate. Use cf-cache-status: HIT vs MISS in the response header to confirm the purge worked.
Zone ID incorrect: The zone ID is a 32-character hex string found in the Cloudflare dashboard under Overview. Copy it exactly, including hyphens.
Rate Limiting: The Cloudflare API allows 1200 purge requests per 5 minutes. If you exceed this, wait before sending more requests.
Additional Troubleshooting
# Check the error message and stack trace for more context
echo "Review the full error output to identify the root cause"
If the above steps do not resolve the issue, examine the complete error message and stack trace. Often the key detail is in the middle of the traceback rather than the final line. Search for the error message in the project documentation or issue tracker for additional solutions.
Prevention
- Use cache tags (
Cache-Tagresponse header) to purge by content group. - Set appropriate
max-ageands-maxageheaders to control cache duration. - Bump asset filenames with content hashes (e.g.,
style.a1b2c3.css) to avoid manual purging. - Use Cloudflare's staging environment for pre-deployment testing.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro