Home / Fix guides / Speed and Core Web Vitals

How to set up a CDN to speed up your website

A CDN (content delivery network) keeps copies of your images, CSS, JavaScript and fonts on servers around the world and serves each visitor from a nearby one. If your site has none, every file travels from your single hosting server, which is slower for anyone far away and for everyone when traffic spikes.

A CDN is a group of servers in many locations that store copies of your static files: images, stylesheets, scripts, fonts and sometimes video. When someone opens your page, those files come from a server close to them instead of from your hosting company's one data centre. Without a CDN, a visitor in Sydney loading a site hosted in Texas waits for every file to cross the planet.

What the problem looks like

Most owners never see the problem directly. They notice symptoms:

  • Pages feel fast for you but slow for customers in other countries or regions.
  • Image-heavy pages (galleries, product listings) load in visible pieces.
  • The site slows down when a newsletter, ad campaign or sale brings a lot of visitors at once.
  • Speed test tools report a slow Largest Contentful Paint (see slow LCP) and long waiting times for the first byte.

A missing CDN is rarely the only cause of a slow site, but it is one of the more affordable fixes.

Why it matters

Search: Google measures real visitor speed through Core Web Vitals. Slow loading of the main image or headline can hold back your scores, and speed is one of many signals used in ranking.

Sales and trust: People leave slow pages, especially on phones. A product page that takes several seconds to show its photo loses buyers who never tell you why.

Resilience: Your hosting server does less work because the CDN answers most file requests. That helps during traffic spikes. Many CDNs also add protection against some kinds of abusive traffic and handle HTTPS for you, though that varies by provider.

How to check if your site uses a CDN

These checks are free and take a few minutes.

  1. Open your site in Chrome, right click, choose Inspect, then open the Network tab and reload the page.
  2. Click an image or a .css file in the list and look at the Headers panel.
  3. Check the response headers. Signs of a CDN include server: cloudflare, cf-cache-status, x-cache, x-amz-cf-id (Amazon CloudFront), or x-served-by.
  4. Look at the file address. If images load from something like cdn.yourdomain.com or a provider's hostname instead of your own domain, a CDN is probably in use.
  5. Run your page through a free tool such as PageSpeed Insights or WebPageTest. Neither has a single "you need a CDN" test, but they show slow server response and long file load times, and WebPageTest's waterfall shows where each file came from.

If your files all come from your own domain and none of those headers appear, you most likely have no CDN. Note that some hosts include one in the package, so check your hosting plan before buying anything.

How to fix it: the two main approaches

Approach 1: put the whole site behind a CDN proxy. You point your domain's nameservers (or DNS records) at a provider such as Cloudflare. Visitors then connect to the CDN, which serves cached files and passes the rest to your server. Cloudflare has a free plan, and this is the simplest route for most small sites. See our Cloudflare guide for the steps.

Approach 2: serve only static files from a CDN hostname. You create a "pull zone" (the wording varies) with a provider such as Bunny, KeyCDN, Fastly or Amazon CloudFront. Its origin is your own site. You get a hostname such as cdn.yourdomain.com, and your site rewrites image, CSS and script addresses to use it. Your pages still come from your server, only the files are offloaded.

In both cases the general order is:

  1. Pick a provider and create an account.
  2. Add your domain or create the pull zone with your site as the origin.
  3. Change DNS (approach 1) or set the CDN hostname in your site or plugin (approach 2). Write down your old DNS settings first so you can go back.
  4. Make sure HTTPS works on the CDN hostname, otherwise browsers show mixed content warnings.
  5. Set sensible cache rules, then test.

Common platforms

PlatformWhere to look
WordPressA caching plugin (WP Rocket, W3 Total Cache, LiteSpeed Cache) usually has a CDN section where you paste the CDN URL. Jetpack's Site Accelerator serves images and files from its own network. See the WordPress guide.
Shopify, Wix, SquarespaceA CDN is already built in. You normally cannot change it.
Nginx or ApacheSet cache headers on static files, then point DNS at a CDN. See the Nginx and Apache guides.
cPanel hostingSome hosts offer Cloudflare in cPanel under a section often called Cloudflare or Domains. It depends on the host.
WooCommerceSame as WordPress, but never cache cart, checkout or account pages.

Cache headers matter

A CDN follows the instructions your server sends in the Cache-Control header. If files are marked as not cacheable, the CDN keeps fetching them from your server and you gain little. Images, CSS, JavaScript and fonts that have versioned names can safely be cached for a long time. Our page on browser caching explains how to set this.

How to confirm the fix worked

  1. Reload the page with the Network tab open and check a file's headers again. You should see the CDN's headers.
  2. Load the same file twice. The second time, a header such as cf-cache-status: HIT or x-cache: Hit means it came from the CDN's copy.
  3. Run WebPageTest from a location far from your server and compare before and after. Look at file load times and the first byte.
  4. Click through the site as a customer: forms, search, login and checkout should all still work.
  5. Check that no browser warnings about mixed or insecure content appear.

Speed measurements vary from run to run, so test a few times and compare typical results, not a single best one.

How to stop it coming back

  • When you change a CSS or image file and the old one still shows, purge the CDN cache (most providers have a button for this) or use new file names.
  • Exclude pages that differ per visitor, such as carts, checkouts, account areas and admin screens.
  • Keep your CDN plugin and settings noted somewhere. A theme change or a plugin update can quietly switch off the CDN URL.
  • If you move hosts or change DNS, re-check that the CDN is still in front of the site.
  • Re-test speed every few months. Week 4 of SiteMonday checks speed and Core Web Vitals on a set schedule and lists problems in a ranked fix list, which is one way to notice a CDN that has dropped out.

SiteMonday finds and explains the issue. Making the change is up to you or your developer.

Step by step for your platform

Questions

Do I need a CDN if my visitors are all in one country?

It still helps by taking load off your server and speeding up repeat file delivery, but the gain is smaller than for a worldwide audience. A host located near your customers plus good caching may be enough for a small local site.

Is a CDN the same as web hosting?

No. Your host stores and runs your website. A CDN sits in front of it and keeps copies of files in many locations. You normally need both.

Will a CDN hurt my SEO?

Not when set up properly. Keep your pages on your own domain and make sure HTTPS works, so search engines see the same content as before.

Can I use a free CDN?

Some providers, including Cloudflare, offer a free plan that covers the needs of many small sites. Features and limits change, so check the provider's current plan details.

Why do I still see old images after setting up a CDN?

The CDN is probably serving a cached copy. Purge the cache from the provider's dashboard, or rename the file so it is treated as new.

Does a CDN speed up my whole website?

It speeds up static files, and with a full proxy it can also cache some pages. Slow code, heavy plugins and a slow database are not fixed by a CDN.

Related problems