When a visitor loads your website, their browser downloads files — HTML, CSS, JavaScript, images, fonts — from your web server. If your server is in London and your visitor is in London, those files arrive quickly. If your server is in London and your visitor is in Edinburgh, Sydney, or New York, there is additional latency caused by the physical distance the data must travel. A Content Delivery Network — CDN — addresses this by distributing copies of your files across servers in multiple geographic locations, so each visitor is served from the nearest one.
How a CDN Works
A CDN operates a network of servers — called Points of Presence or PoPs — distributed around the world. When you connect your website to a CDN, static files (images, CSS, JavaScript, fonts) are cached at these edge servers. When a visitor requests your site, the CDN automatically serves those static files from the PoP geographically closest to them, while dynamic content (PHP-generated pages, database queries) still comes from your origin server.
The result is that large, heavy files — particularly images — are delivered faster to all visitors, regardless of where they are, because they come from a nearby server rather than your single origin server.
What a CDN Does (and Does Not Do)
A CDN does:
- Reduce page load times, particularly for image-heavy pages
- Reduce load on your origin server by serving static files from edge nodes
- Provide some DDoS protection by absorbing traffic spikes at the edge
- Improve performance for visitors outside your server's location
A CDN does not:
- Make a slow server faster at generating dynamic pages
- Fix problems caused by unoptimised code or too many plugins
- Replace good hosting — it complements it
CDN Options: Free and Paid
Cloudflare (free tier) is the most widely used option for small and medium websites. You change your domain's nameservers to Cloudflare, and it acts as a reverse proxy, caching static content at its global network and also providing a WAF, DDoS protection, and analytics. The free tier is generous and sufficient for most small websites.
BunnyCDN, KeyCDN and similar services are pay-per-use CDNs with very low rates — typically a fraction of a penny per GB — that can be used if you prefer not to change your nameservers.
Some hosting providers include a built-in CDN. Eazyhosting's platform includes CDN capabilities to improve performance for visitors.
Should Your Website Use a CDN?
For most websites, a CDN provides a meaningful performance improvement at little or no cost. Cloudflare's free tier is so easy to set up and provides enough benefit that it is worth using for nearly any website. Specific situations where a CDN is particularly valuable:
- Sites with lots of images or downloadable files
- Sites serving visitors across the UK or internationally
- Sites experiencing traffic spikes that occasionally overwhelm the origin server
- Sites that want basic DDoS protection without extra cost
Setting Up Cloudflare
- Create a free account at cloudflare.com
- Add your domain and let Cloudflare scan your existing DNS records
- Update your domain's nameservers at your registrar to Cloudflare's nameservers
- Wait for DNS propagation (usually a few minutes to a couple of hours)
- Your site now passes through Cloudflare's network — caching, protection, and CDN are all active
Common Mistakes
- Caching dynamic pages too aggressively. A CDN caching logged-in user pages or checkout pages can cause incorrect content to be served. Configure cache rules carefully for dynamic content.
- Not purging the cache after making changes. If you update your site and the CDN serves cached old versions, visitors do not see your changes. Purge the cache after significant updates.
- Expecting a CDN to fix underlying performance problems. A CDN makes a fast site faster. It will not make a fundamentally slow site fast.
A CDN is one of the most straightforward performance improvements available, and at the free tier, there is very little reason not to use one. Set it up once and it works quietly in the background.
Need hosting that includes built-in CDN capabilities? Learn about Eazyhosting's CDN feature, or view our hosting plans.