performanceCDNWordPressPerformance

CDN for WordPress: Complete Guide to Speeding Up Your Site

CDN for WordPress: Complete Guide to Speeding Up Your Site

A Content Delivery Network (CDN) serves your site's files from servers close to your visitors. This guide explains how CDNs work and how to set one up for WordPress.


What Is a CDN?

Without a CDN, all requests go to your origin server:

Visitor (Tokyo) → Origin Server (New York) → Response

Distance: ~10,000 km

Latency: 150-200ms

With a CDN:

Visitor (Tokyo) → CDN Edge (Tokyo) → Response

Distance: ~10 km

Latency: 5-10ms

Result: Faster page loads for visitors everywhere.


What CDNs Cache

A CDN typically caches static assets:

Asset TypeExamplesCacheable
Images.jpg, .png, .webp
Stylesheets.css
JavaScript.js
Fonts.woff2, .ttf
Videos.mp4, .webm
HTML.htmlDepends
API responsesDynamicUsually ❌

For WordPress, most CDN configurations cache assets but not dynamic HTML pages.


Popular CDN Options

Cloudflare (Recommended)

Pricing:

  • Free tier available
  • Pro: $20/month
  • Business: $200/month

Pros:

  • Free tier is excellent
  • DNS + CDN + Security
  • Easy setup
  • DDoS protection
  • SSL included

Cons:

  • Full page caching requires config
  • APO costs extra ($5/month)

BunnyCDN

Pricing: Pay-as-you-go (~$0.01/GB)

Pros:

  • Very affordable
  • Fast global network
  • Simple pricing
  • Good EU coverage

Cons:

  • Less feature-rich than Cloudflare
  • No free tier

KeyCDN

Pricing: Pay-as-you-go (starting $0.04/GB)

Pros:

  • Good performance
  • Real-time analytics
  • Easy WordPress integration

Cons:

  • Minimum $49 credit to start
  • Less known than alternatives

Fastly

Pricing: Pay-as-you-go (enterprise-focused)

Pros:

  • Extremely fast edge
  • Instant purge
  • Advanced edge computing

Cons:

  • Expensive at scale
  • More complex setup

Setting Up Cloudflare

Step 1: Create Account

1. Go to cloudflare.com

2. Sign up (free)

3. Add your site

Step 2: Update Nameservers

Cloudflare provides nameservers like:

anna.ns.cloudflare.com

bob.ns.cloudflare.com

Update these at your domain registrar.

Step 3: Configure Settings

Speed → Optimization:

  • Auto Minify: CSS, JavaScript, HTML
  • Brotli: On

Caching → Configuration:

  • Caching Level: Standard
  • Browser Cache TTL: 4 hours (or respect headers)

Security → Settings:

  • Security Level: Medium
  • Challenge Passage: 30 minutes

Step 4: Install WordPress Plugin (Optional)

Install "Cloudflare" plugin:

1. Plugins → Add New → Search "Cloudflare"

2. Install and activate

3. Connect API key

4. Enable automatic cache purge

Step 5: Enable APO (Optional)

Automatic Platform Optimization ($5/month) caches full HTML pages:

1. Speed → Optimization → Cloudflare APO

2. Enable APO

3. Install Cloudflare plugin if not already

This is the closest to full page caching you'll get with WordPress on Cloudflare.


Setting Up BunnyCDN

Step 1: Create Pull Zone

1. Sign up at bunny.net

2. Add credit (minimum $10)

3. Create Pull Zone:

- Origin URL: your WordPress URL

- Zone name: choose a name

Step 2: Get CDN URL

You'll receive a URL like: mysite.b-cdn.net

Step 3: Configure WordPress

Option A: Plugin

Install "BunnyCDN" plugin:

1. Plugins → Add New → Search "BunnyCDN"

2. Configure CDN hostname

3. Set directories to include

Option B: CDN Enabler

Use "CDN Enabler" plugin:

1. Install and activate

2. Set CDN hostname: mysite.b-cdn.net

3. Included directories: wp-content,wp-includes

Step 4: Custom Domain (Optional)

1. Create CNAME: cdn.yoursite.commysite.b-cdn.net

2. Add custom hostname in Bunny dashboard

3. Enable SSL


WordPress CDN Plugins

WP Rocket (Paid)

Includes CDN integration:

  • Works with any CDN
  • Automatic asset URL rewriting
  • Preloading

LiteSpeed Cache (Free)

For LiteSpeed servers:

  • QUIC.cloud CDN included
  • Full page caching
  • Image optimization

W3 Total Cache (Free)

CDN integration:

  • Supports many CDN providers
  • Complex but powerful
  • Manual configuration

Perfmatters (Paid)

Lightweight with CDN:

  • Simple rewrite rules
  • Works with any CDN
  • Minimal bloat

CDN Best Practices

1. Set Proper Cache Headers

In your .htaccess or server config:

Images - cache for 1 year

jpegpnggifwebpsvgico)$">

Header set Cache-Control "public, max-age=31536000, immutable"

CSS/JS - cache for 1 year (use versioning)

Header set Cache-Control "public, max-age=31536000, immutable"

Fonts - cache for 1 year

woff2ttfeot)$">

Header set Cache-Control "public, max-age=31536000, immutable"

2. Use Query Strings for Cache Busting


3. Purge Cache After Updates

After theme or content updates:

  • Clear CDN cache
    • Clear WordPress cache
    • Test the site

    4. Monitor Performance

    Track:

    • Cache hit ratio (aim for 90%+)
    • Response times
    • Bandwidth usage

    Common CDN Issues

    Issue: Changes Not Showing

    Cause: Browser or CDN cache serving old content

    Fix:

    1. Clear CDN cache

    2. Clear browser cache

    3. Check cache TTL settings

    Issue: Mixed Content Warnings

    Cause: Some assets loaded over HTTP

    Fix:

    1. Force HTTPS in WordPress settings

    2. Update hardcoded HTTP URLs

    3. Use relative URLs or //

    Issue: 404 Errors on CDN

    Cause: CDN can't reach origin

    Fix:

    1. Verify origin URL is correct

    2. Check firewall isn't blocking CDN

    3. Verify SSL on origin

    Issue: Slow First Load

    Cause: Cache is cold (not populated)

    Fix:

    1. Pre-warm cache by visiting pages

    2. Use CDN preload feature if available

    3. Accept that first hits are slower


    CDN vs. Modern Hosting

    Here's the interesting thing: modern static hosting includes CDN by default.

    Traditional WordPress + CDN

    1. Request comes in
    

    2. CDN checks cache

    3. If miss, request goes to origin

    4. WordPress generates HTML (PHP + MySQL)

    5. Response returns through CDN

    6. CDN caches for next time

    Complexity: High. Multiple layers to configure.

    Static Site on Modern Hosting

    1. Request comes in
    

    2. Edge server returns pre-built HTML

    3. Done.

    With Vercel, Netlify, or Cloudflare Pages:

    • No CDN configuration needed
    • Files are at the edge by default
    • Pre-built = always fast
    • No cache warming required

    Comparison

    AspectWordPress + CDNStatic on Edge
    SetupComplexAutomatic
    First requestSlow (origin hit)Fast (pre-built)
    Cache managementManualNone needed
    Cache invalidationTrickyAutomatic on deploy
    CostCDN + hostingUsually free tier
    Global performanceGoodExcellent

    When You Need a CDN

    WordPress without CDN is acceptable for:

    • Small/local audience
    • Low traffic sites
    • Server geographically near users

    WordPress needs a CDN for:

    • Global audience
    • High traffic
    • Image-heavy sites
    • E-commerce

    You don't need to configure a CDN for:

    • Static sites on Vercel/Netlify/Cloudflare Pages
    • Edge-hosted applications
    • JAMstack sites

    FAQ

    Q: Is Cloudflare free good enough?

    Yes for most sites. Free tier includes CDN, DDoS protection, and SSL. APO ($5/month) adds full page caching for WordPress.

    Q: Can I use multiple CDNs?

    Technically yes, but usually unnecessary and adds complexity.

    Q: How do I know if CDN is working?

    Check response headers for CDN-specific headers (like cf-cache-status: HIT for Cloudflare). Use tools like curl -I or browser dev tools.

    Q: Will CDN help my SEO?

    Faster sites rank better, so yes. CDN improves Core Web Vitals metrics. Learn more about Core Web Vitals →

    Q: What about image optimization?

    CDNs help deliver images faster, but you should still compress them. See our image optimization guide →


    Conclusion

    CDNs significantly improve WordPress performance, but require configuration and management:

    CDNBest ForPrice
    CloudflareMost sitesFree-$20/mo
    BunnyCDNBudget-conscious~$1-5/mo
    KeyCDNSimple setupPay-as-you-go

    For the simplest experience, consider static hosting where CDN is automatic. No configuration, no cache purging, no complexity.

    Related guides:

    Learn about modern hosting alternatives →

    Share:

    Related Articles

    View all

    Ready to Migrate Your WordPress Site?

    Use our free tool to export your WordPress content in minutes.

    Start Free Migration