Cloudflare CDN Integration
Performance Toolkit integrates with Cloudflare CDN to serve your content globally from edge locations, reducing latency and improving performance worldwide.
What is Cloudflare?
Cloudflare is a global Content Delivery Network (CDN) that:
- Caches your site on servers worldwide
- Serves content from the location closest to each visitor
- Reduces origin server load
- Improves performance globally
- Provides security features (DDoS protection, WAF)
With Cloudflare, a US visitor gets content from US servers, a UK visitor from UK servers, etc.—dramatically faster than serving from a single origin server.
Prerequisites
- Cloudflare account — sign up free at cloudflare.com
- Domain on Cloudflare — point your domain's nameservers to Cloudflare (free)
- Cloudflare API token — generate in your account settings
- Zone ID — your Cloudflare domain ID (visible in account dashboard)
Getting Your API Token and Zone ID
Step 1: Get Zone ID
- Log in to Cloudflare dashboard
- Select your domain
- Copy the Zone ID from the right sidebar (under "API")
Step 2: Create API Token
- In Cloudflare dashboard, click your profile icon (top right)
- Go to My Profile → API Tokens
- Click Create Token
- Choose Edit zone DNS or Custom token template
- Configure scopes:
- Set to your specific zone (domain)
- Grant
Cache Purgepermission - Grant
Zone Readpermission
- Create token and copy the value
Setting Up Cloudflare Integration
- Go to Performance Toolkit → CDN & Integrations
- Select Provider: Cloudflare
- Paste your API Token
- Paste your Zone ID
- Check Auto-purge on content update (recommended)
- Click Test Connection to verify credentials
- Click Save changes
Features
Test Connection
Verifies your API token and Zone ID are correct before saving.
- Enter API token and Zone ID
- Click Test Connection
- Success ✅ — credentials are valid
- Error ❌ — check token/zone ID and try again
Purge Cache
Clears all cached content from Cloudflare edge servers.
Use when:
- You made manual changes that should appear immediately
- Cache seems stale
- After major site updates
- Before client testing/demos
- Go to CDN & Integrations
- Click Purge Cache
- Cloudflare clears all cached files
- Content re-caches on next user request
Auto-purge on Content Update
When enabled, cache is automatically purged when:
- Posts/pages are published or updated
- Draft changes are saved
- Comments are approved
- Theme/plugin changes occur
- Settings are updated
Recommended — Enable this to keep Cloudflare cache in sync with your site changes. Slight overhead for automatic purge requests.
Cache Behavior
What Gets Cached
Cloudflare caches:
- ✅ Static HTML (if page cache enabled in Performance Toolkit)
- ✅ CSS files
- ✅ JavaScript files
- ✅ Images and media
- ✅ Fonts
- ✅ PDFs and downloads
What Doesn't Get Cached
- ❌ HTML with Set-Cookie headers (user-specific pages)
- ❌ Admin pages (
/wp-admin,/wp-login.php) - ❌ Comment forms
- ❌ Dynamic content (unless explicitly configured)
Combining with Page Cache
For best performance, use both Performance Toolkit page caching AND Cloudflare:
- Page Cache (Performance Toolkit) — caches on your origin server
- Cloudflare Cache — caches on global edge locations
Combined benefit:
- Origin server stays fast (local cache)
- Global visitors stay fast (edge cache)
- Origin only hit on cache miss (rare after first few visits)
Performance Impact
Typical improvements from Cloudflare integration:
| Metric | Improvement |
|---|---|
| Response time (global) | 30-70% faster |
| Time to First Byte | 20-40% improvement |
| Page load time | 10-30% faster |
| Origin server load | 50-80% reduced |
| Bandwidth costs | 10-40% reduced |
Results vary based on:
- Geographic distribution of traffic
- Origin server location
- Content types
- Cache TTL settings
Advanced Configuration
Cache Rules (in Cloudflare Dashboard)
Fine-tune what Cloudflare caches:
- Log in to Cloudflare dashboard
- Go to your domain
- Click Caching → Cache Rules
- Configure rules for specific URL patterns
- Examples:
- Cache homepage for 1 hour
- Cache
/blog/*for 24 hours - Don't cache
/api/*
Browser Cache TTL
Set how long browsers cache your content:
- In Cloudflare: Caching → Browser Cache TTL
- Recommended: 2-4 hours
- Longer = better performance but older content in some browsers
Purge Cache from Cloudflare Dashboard
Alternative to using Performance Toolkit:
- Cloudflare dashboard
- Select domain → Caching → Configuration
- Click Purge Everything
- Wait for purge to complete
Troubleshooting
Test Connection fails
- Check API token — copy from Cloudflare again, verify no extra spaces
- Check Zone ID — make sure it's specifically for that domain
- API token permissions — verify token has Cache Purge permissions
- Rate limiting — wait a few minutes and try again
Cache not updating after publishing
- Verify auto-purge is enabled — check CDN & Integrations settings
- Check Cloudflare cache rules — may override auto-purge
- Manually purge — click Purge Cache button to clear immediately
Performance didn't improve
- Cloudflare benefits depend on traffic distribution
- Local traffic (single country) sees less benefit
- Global traffic sees major improvement
- Check cache hit rate — Cloudflare dashboard shows % of cached requests
- Combine with other optimizations — CDN is one piece of larger strategy
"Unauthorized" errors
Usually token revoked or permissions changed:
- Generate new API token in Cloudflare
- Update token in Performance Toolkit
- Test connection again
Best Practices
- ✅ Enable both Performance Toolkit page cache AND Cloudflare
- ✅ Use auto-purge on content update
- ✅ Monitor cache hit rate in Cloudflare dashboard
- ✅ Test performance improvements with Google PageSpeed
- ✅ For HTTP API responses, set appropriate cache headers
- ✅ Keep API token secure; never share publicly
Security Notes
- Keep your API token secure
- Never commit to version control
- Cloudflare provides DDoS protection and WAF on free plan
- Use Cloudflare's security settings for additional hardening
Free vs Paid Plans
This integration works on all Cloudflare plans:
| Feature | Free | Pro+ |
|---|---|---|
| Global CDN | ✅ | ✅ |
| Cache purge | ✅ | ✅ |
| API access | ✅ | ✅ |
| DDoS protection | ✅ | ✅ Advanced |
| WAF | ✅ | ✅ Advanced |
Next Steps
- Set up on staging first to test
- Monitor Dashboard and System Status metrics
- Verify performance improvements
- Roll out to production when confident
- Continue monitoring performance metrics
Cloudflare + Performance Toolkit = a powerful combination for global performance.