Jekyll Cloudflare Cache Purge

I currently host this site on Digital Ocean via their Apps offering.

This allows me to push to main on a private repo, then have DO build the site and deploy it to their servers without much maintenance overhead on my part.

CloudFlare sits in front of my site, caching and providing optimisations to images and so on as hell as taking care of SSL. The caching part is great, but if I deploy to my site and decide to change the style of something, it can take some time before the new version of the page is rendered to the end user.

Enter jekyll-cloudflare-cache-purge. This jekyll plugin triggers a POST to the CloudFlare API once my site builds, purging the cache, and allowing the new version of the site to be picked up and sent to visitors.

Usage

Add the following to your site’s Gemfile

gem 'jekyll-cloudflare-cache-purge'

Add the plugin to your _config.yml:

# Build settings
plugins:
  - jekyll-feed
  - jekyll-cloudflare-cache-purge

Define two env vars on the system that builds and hosts your blog:

CLOUDFLARE_ZONE="<Get this value from your CF dashboard>"
CLOUDFLARE_API_TOKEN="<Create an api key just for purging the cache in CF>"

…and that’s it. Once your blog has built, you should see a line appear in the build output that reads Cloudflare Cache: Purged