Short answer: To configure a CDN for WordPress, sign up with a CDN provider, point your DNS to the CDN (or use a plugin), configure caching rules for static files, enable SSL, and test with browser tools. Most setups take 30-60 minutes.
Key takeaways
- Choose a CDN provider that fits your traffic and budget.
- Use a plugin or DNS change to connect WordPress to CDN.
- Cache static assets like CSS, JS, and images for best performance.
- Ensure SSL is configured end-to-end to avoid mixed content.
- Test and purge cache after making changes to see the effect.
What you will find here
If your WordPress site loads slowly for visitors far from your server, a CDN is the fix. A Content Delivery Network stores copies of your static files on servers around the world and delivers them from the nearest location. It reduces latency and offloads traffic from your origin server. But the real benefit comes only after you configure it correctly. Here is a straight-to-the-point guide on how to configure CDN for WordPress, step by step.
What Does a CDN Actually Do for WordPress?
A CDN caches static resources — images, CSS, JavaScript, fonts — and serves them from edge servers close to the visitor. That means faster load times, lower server load, and often better Core Web Vitals. But not all CDN setups are equal. A misconfigured CDN can break your site or cause stale content to be served. So understanding the mechanics first helps you avoid common mistakes.
Step 1: Choose a CDN Provider
The first step is picking a provider. Popular options include Cloudflare, Bunny.net, StackPath, and KeyCDN. Some are free (Cloudflare has a generous free tier), others are pay-as-you-go. Your choice depends on your budget, technical comfort, and required features like custom caching rules or DDoS protection.
What to Look For
- Global edge presence: more edge locations = lower latency for users worldwide.
- Easy WordPress integration: plugins or one-click setup save time.
- SSL support: must handle HTTPS without breaking mixed content rules.
- Custom cache rules: ability to set TTL per file type or URL path.

Step 2: Point Your DNS to the CDN
Two approaches exist: change your domain’s nameservers to the CDN (like Cloudflare) or use a CDN plugin to rewrite URLs (like Bunny.net with a WordPress plugin). The first method is simpler because it handles all traffic through the CDN by default. The second gives you more granular control but requires a plugin.
If you go the nameserver route, update the nameserver records at your domain registrar to the ones provided by the CDN. Propagation takes a few minutes to up to 48 hours, but typically under an hour. If you use a plugin, install it and enter your CDN’s origin URL or pull zone URL. The plugin will rewrite asset URLs to point to the CDN.
Step 3: Configure Caching Rules
Caching rules tell the CDN which files to cache and for how long. Default settings often cache everything, which can cause trouble for dynamic content or logged-in users. You want to cache static assets aggressively (images, CSS, JS) but avoid caching HTML pages unless you have a static site or use a full-page cache plugin that purges properly.
Here is a typical caching rule set for WordPress:
| File Extension | Cache Duration | Notes |
|---|---|---|
| .jpg, .png, .gif, .webp | 30 days | Use cache-busting filenames for updates |
| .css, .js | 7–30 days | Versioning in filenames is critical |
| .woff, .woff2 | 30 days | Fonts rarely change |
| .html | No cache or short TTL | Use origin cache-control header |
Set a default TTL of, say, 1 hour for HTML if you use a full-page cache plugin that purges on post update. Otherwise, bypass HTML entirely to avoid serving stale content.

Step 4: Handle SSL and Mixed Content
If your site runs on HTTPS (it should), your CDN must also serve HTTPS. Most CDNs offer free SSL certificates via Let’s Encrypt or their own CA. Enable it in your CDN dashboard. Then make sure your WordPress site’s URLs use https:// and that all assets are loaded over HTTPS. Use a plugin like Really Simple SSL or search-replace legacy http:// references in your database.
A common pitfall: if your CDN pulls assets from your origin via HTTP while serving them via HTTPS, you might get mixed content warnings. Configure the CDN to fetch from origin using HTTPS as well, and ensure your origin server has a valid SSL certificate (even for internal use).
Step 5: Test and Validate Your Setup
After configuring, test that static files are being served from the CDN. Open your site, view the page source, and look for asset URLs. They should contain your CDN domain (e.g., cdn.yoursite.com or a CDN provider domain). Use browser DevTools (Network tab) to confirm the server header shows the CDN’s name. Tools like Pingdom or GTmetrix can show you the serving location.
Also check that your site still looks and functions correctly — click around, test forms, and view the site while logged out. If something breaks, review your caching rules and ensure the CDN is not caching admin or login pages (set bypass rules for /wp-admin/, /wp-login.php, and any dynamic API endpoints).
Step 6: Purge Cache When Needed
After making content or design changes, ask the CDN to clear its cache. Most providers offer a “purge” button in the dashboard. If you use a WordPress CDN plugin, it often auto-purgues when you update posts. Otherwise, manually purge after each deployment. Check the purge — if old files still show, wait a few minutes and try again.
For a deeper look at the entire process, including pitfalls to avoid, see our full article on How to Configure CDN for WordPress: Step-by-Step.
Frequently asked questions
What is the best CDN for WordPress?
The best CDN depends on your needs. Cloudflare is great for a free, all-in-one solution. Bunny.net offers low-cost, high-performance edge caching with a simple setup. For enterprise, StackPath or Akamai provide advanced features. Test a few and measure your load times.
Does a CDN affect WordPress admin?
Yes, if misconfigured. You should bypass caching for /wp-admin/ and /wp-login.php to avoid serving stale admin pages or breaking login sessions. Most CDNs allow you to set rules to exclude these paths from caching.
Do I need a plugin to use a CDN with WordPress?
Not always. If you change your DNS nameservers (like with Cloudflare), no plugin is needed. But plugins like W3 Total Cache or Bunny CDN make setup easier and offer features like cache purging on post update. They also rewrite asset URLs automatically.
How long does it take for a CDN to start working?
DNS propagation can take from a few minutes to 48 hours, but usually under an hour. Once DNS resolves to the CDN, caching begins immediately. However, the first request from each edge location may hit your origin until the cache is populated.
Will a CDN fix slow TTFB (Time to First Byte)?
A CDN can improve TTFB for geographically distant users by terminating the initial connection close to them. However, if the server itself is slow due to poor code or hosting, a CDN won’t fully fix that. Optimize your origin too.