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: Default: |
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
- Go to API Tokens.
- Click "Create Token".
- Go to "Create Custom Token" at the bottom and click on "Get started".
- Enter a token name (e.g.
"Production Site Purge Token"). - Set Permissions to "Zone", "Cache Purge", "Purge".
- Set Zone Resources to "Include", "Specific zone", "<your production zone>".
- Click "Continue to summary".
- Click "Create Token".
- 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.