Worker Recipe: Cache purge proxy

recipe-exchange

#1

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 domain.com/__purge_cache?zone=[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

Note:
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
#2

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

Especially when caching everything!


#3

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.