Worker Recipe: Cache purge proxy



The following service worker example works as a proxy to the Cloudflare API, allowing you to purge cache for any zone within your Cloudflare account by just sending a request to[zone_id]

The benefits?

  • Easily purge cache upon deployment by calling the /__purge_cache endpoint through a webhook
  • No need to expose global API keys to third party (deployment) tools

You may want to add further limitations by purging cache by cache tags, limit the script to only work for certain zones, or implement some sort of authentication/request verification.

Purge zone cache via API with X-Auth-User-Service-Key
Cache only API key

Thanks for sharing! This will be really useful :smiley:

Especially when caching everything!


I just added this to a couple of sites I manage. Now when they update content, they can click on a bookmark to immediately purge the cache.