Using CDN with WordPress to improve website speed

A WordPress site that takes longer than 3 seconds to load loses more than 53% of visitors according to Google research. Google also factors Core Web Vitals into rankings, making speed a direct SEO signal. A CDN (Content Delivery Network) has become essential for any WordPress site that needs strong performance.

This guide explains what a CDN is, why it speeds up WordPress, and walks you through setting up Cloudflare CDN step by step — including integration with popular cache plugins and automatic cache purging.

What Is a CDN in the WordPress Context?

A CDN is a network of servers distributed globally that stores cached copies of static files — images, CSS, JavaScript — from your website, then delivers them to visitors from the server geographically nearest to them.

Example: if your WordPress is hosted in Bangkok but a visitor comes from Japan, without a CDN they receive files from Bangkok (high latency). With a CDN, a copy sits at a Tokyo data center, loading far faster.

Why CDN Makes WordPress Faster

A typical WordPress site contains many static files — images, fonts, CSS, JavaScript — that load on every page view. A CDN helps in three key ways:

Real numbers: Testing Cloudflare CDN on a mid-size WordPress site shows average page load time reductions of 40–60% for international visitors.

CDN and Core Web Vitals: The SEO Connection

Google confirmed that Core Web Vitals became a ranking signal in 2021 and remains critical through 2026. A CDN directly improves three Core Web Vitals metrics for WordPress sites.

Largest Contentful Paint (LCP)

LCP measures how long it takes the largest visible element on the page (usually a hero image or main heading) to load. The goal is LCP ≤ 2.5 seconds. CDN improves LCP by:

First Input Delay (FID) / Interaction to Next Paint (INP)

CDN helps reduce JavaScript execution time by delivering pre-minified JS files from edge cache faster. This frees up the browser's main thread sooner. A good INP score is ≤ 200ms.

Cumulative Layout Shift (CLS)

CDN does not directly fix CLS, but faster delivery of fonts and CSS from edge cache allows the browser to compute the correct layout earlier, reducing layout shifts caused by late-loading fonts.

PageSpeed tip: In Google PageSpeed Insights, look for "Serve static assets with an efficient cache policy." If your CDN is set up correctly, static assets should show a Cache-Control header of at least one year (31,536,000 seconds).

Popular Free CDN Options for WordPress

1. Cloudflare (Free — Most Recommended)

Cloudflare is the most popular CDN for WordPress because the free plan includes CDN, DDoS protection, SSL, firewall, and even has an Edge Server in Bangkok, Thailand.

2. BunnyCDN (Cheapest for High Traffic)

BunnyCDN offers pay-as-you-go pricing at approximately $0.01/GB with no monthly minimum. Ideal for sites wanting CDN via Pull Zone without changing nameservers.

3. Statically (Free for Static Assets)

Statically is a completely free CDN focused on static assets like images, CSS, and JS. No signup required — just change asset URLs to go through the CDN endpoint.

CDN Options Compared: 2026 Overview

Before choosing a CDN, compare features and pricing to match your site's needs. The table below summarizes the main options for WordPress sites:

CDN Pricing Asia PoP Setup Best For
Cloudflare Free Free Bangkok (BKK PoP) Change NS All site sizes
BunnyCDN $0.01–0.03/GB Singapore Pull Zone URL High traffic
Statically Free Multiple Asia Rewrite URLs Small static-only
KeyCDN $0.04/GB (Asia) Singapore, Tokyo Pull/Push Zone Developers

For WordPress sites hosted at AsiaGB Hosting in Thailand, Cloudflare Free is the recommended first choice. The Bangkok PoP delivers exceptionally low latency for Thai users, with no cost involved.

Step-by-Step: Setting Up Cloudflare CDN with WordPress

Step 1: Create a Cloudflare Account and Add Your Domain

  1. Go to cloudflare.com and sign up for a free account
  2. Click Add a Site and enter your domain, e.g., example.com
  3. Select the Free plan
  4. Cloudflare automatically scans your existing DNS records — verify they are all correct

Step 2: Change Your Nameservers

Cloudflare provides two new nameservers such as aria.ns.cloudflare.com and brad.ns.cloudflare.com. Update these at your domain registrar.

  1. Log in to your registrar (e.g., AsiaGB, Namecheap)
  2. Navigate to DNS / Nameserver settings for your domain
  3. Replace the nameservers with the two values Cloudflare provides
  4. Wait 1–48 hours for DNS propagation (usually much faster)

Important: Before changing nameservers, confirm Cloudflare imported all DNS records correctly — especially MX records for email. Missing MX records will break incoming email after the nameserver change.

Step 3: Configure SSL/TLS Mode

In Cloudflare Dashboard, go to SSL/TLS → Overview and select the correct mode:

Step 4: Configure Cache Rules for WordPress

Cloudflare does not cache dynamic PHP content by default, but automatically caches images and static files. Add Page Rules or Cache Rules to bypass cache on WordPress Admin:

# Page Rule: Bypass Cache for WordPress Admin
# URL Pattern:
yourdomain.com/wp-admin/*
# Setting:
Cache Level: Bypass

# Page Rule: Aggressive Cache for Static Files
yourdomain.com/wp-content/*
# Setting:
Cache Level: Cache Everything
Edge Cache TTL: 1 month

Step 5: Enable Helpful Cloudflare Features

Configuring Cache Headers Correctly for WordPress CDN

For a CDN to perform well, your Origin server must return correct Cache-Control headers. Without them, the CDN either will not cache content at all or caches it for too short a time.

Check Current Cache Headers

Use curl to inspect the response headers from your origin:

curl -I https://yourdomain.com/wp-content/themes/mytheme/style.css

Headers you should see (when a cache plugin is configured correctly):

Cache-Control: public, max-age=31536000
Expires: [date one year in the future]
Vary: Accept-Encoding

Set Cache Headers via .htaccess

If your plugin does not set headers automatically, add the following to your WordPress .htaccess file:

<IfModule mod_expires.c>
  ExpiresActive On
  # Images: cache for 1 year
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/png  "access plus 1 year"
  # CSS / JavaScript: cache for 1 month
  ExpiresByType text/css              "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  # Fonts: cache for 1 year
  ExpiresByType font/woff2 "access plus 1 year"
</IfModule>

<IfModule mod_headers.c>
  # Force public cache for static files
  <FilesMatch "\.(css|js|jpg|jpeg|webp|png|gif|svg|woff2)$">
    Header set Cache-Control "public, max-age=31536000"
  </FilesMatch>
  # Never cache PHP (dynamic content)
  <FilesMatch "\.php$">
    Header set Cache-Control "no-cache, no-store, must-revalidate"
  </FilesMatch>
</IfModule>

Important: Always use versioning or cache-busting when updating CSS/JS files. For example, append ?ver=2.1 to the URL. With a one-year cache and no versioning, visitors will continue seeing old files until the cache naturally expires.

Verify CDN Cache Status

After configuration, verify that Cloudflare cache is active:

curl -I https://yourdomain.com/wp-content/themes/mytheme/style.css | grep -i "cf-cache"
# cf-cache-status: HIT   → CDN cache is working
# cf-cache-status: MISS  → CDN has not cached yet (first request)
# cf-cache-status: BYPASS → CDN is skipping cache (check Page Rules)

WordPress Plugins That Work with CDN

LiteSpeed Cache (Recommended for AsiaGB Hosting)

LiteSpeed Cache works best with LiteSpeed Web Server (used on AsiaGB Hosting). It includes built-in CDN integration supporting Cloudflare and others.

WP Rocket (Premium — Most Comprehensive)

WP Rocket is the most popular premium cache plugin with full CDN integration for Cloudflare, BunnyCDN, and others. Easy to configure and consistently outperforms most free alternatives.

Purging CDN Cache After WordPress Updates

When you publish or update a post, the CDN may still serve cached old content. You need to purge the cache so the CDN fetches fresh content from your Origin.

Purge via Cloudflare Dashboard

  1. Log in to Cloudflare and select your domain
  2. Go to Caching → Configuration
  3. Click Purge Everything or Custom Purge for specific URLs

Automatic Purge with Plugins

LiteSpeed Cache and WP Rocket both support Cloudflare API integration for automatic cache purging on every post publish or update.

Common CDN Problems with WordPress and How to Fix Them

Setting up CDN with WordPress can surface unexpected issues. Knowing the most common problems and their fixes in advance will save considerable troubleshooting time.

Problem 1: Mixed Content Warning (HTTP + HTTPS)

After enabling Cloudflare CDN with HTTPS, browsers sometimes show a "Mixed Content" warning because WordPress is still loading some resources over HTTP.

Problem 2: Redirect Loop (ERR_TOO_MANY_REDIRECTS)

This typically happens when Cloudflare SSL Mode is set to "Flexible" while your origin already has SSL.

Problem 3: WordPress Admin Is Slow or Login Fails

This occurs when Cloudflare caches admin pages.

Problem 4: Updated Images Still Showing the Old Version

The CDN has cached the old image and does not automatically fetch the updated version from origin.

Problem 5: E-Commerce Checkout Issues

WooCommerce checkout or payment pages may fail because the CDN caches these dynamic pages.

Measuring Results with PageSpeed Insights

After configuring CDN, measure your results with Google PageSpeed Insights (pagespeed.web.dev) or GTmetrix to compare before and after.

Key metrics to check after enabling CDN:

Pro tip: Open Chrome DevTools → Network tab and check response headers on CSS/JS files. If you see cf-cache-status: HIT, Cloudflare CDN is working correctly.

Fast WordPress Hosting with Cloudflare CDN Support

AsiaGB Hosting fully supports Cloudflare CDN, using DirectAdmin, SSD storage, free SSL, and 99% Uptime. Starting at 500 THB/year with no hidden fees.

View Hosting Plans →