Set up push invalidation for Cloudflare

Push invalidation is enabled by adding the Cloudflare purge credentials to the CDN section of the configuration service.

curl --request POST \
  --url https://admin.hlx.page/config/{org}/sites/{site}/cdn.json \
  --header 'content-type: application/json' \
  --data '{
 "prod": {
  "host": "{production host}",
  "type": "cloudflare",
  "plan": "enterprise",
  "zoneId": "{cloudflare_zone_id}",
  "apiToken": "{cloudflare_api_token}"
 }
}'

Configuration properties:

Property Value Description
host <Production Host> Host name of the production site, e.g. www.yourdomain.com
type cloudflare
plan e.g. free

Values: free, pro, business, enterprise.

Default: free.

zoneId <Cloudflare Zone ID> ID of the production zone.
apiToken <Cloudflare API Token> Cloudflare API token for purging. Supports secret references.

Create the Cloudflare API token

  1. Go to API Tokens.
  2. Click "Create Token".
  3. Go to "Create Custom Token" at the bottom and click on "Get started".
  4. Enter a token name (e.g. "Production Site Purge Token").
  5. Set Permissions to "Zone", "Cache Purge", "Purge".
  6. Set Zone Resources to "Include", "Specific zone", "<your production zone>".
  7. Click "Continue to summary".
  8. Click "Create Token".
  9. Copy the generated token value.

Validate the credentials

You can validate the credentials with this tool.

Notes

All non-production / lower environments that are fronted by a CDN, should set the x-push-invalidation header to disabled and still honor the origin cache control headers, which will automatically result in short-lived TTLs. See Push Invalidation Worker Settings for more details.

Only sites on the enterprise plan will be surgically purged by url and cache key. A Purge All will be performed instead on non-enterprise sites every time an author publishes a content change.