A CDN (Content Delivery Network) is a network of servers located in various parts of the world, which serves copies of a website’s content from the server geographically closest to the visitor.
How does it work?
Without a CDN, every visitor downloads the page from the hosting server, wherever they are. When using a CDN, the visitor’s browser connects to the nearest CDN server. If a fresh copy (cache) of the requested file is already available there, the visitor receives it immediately; if not, the CDN retrieves it from the hosting server (the so-called origin server), delivers it, and stores it for the next visitor.
By default, Cloudflare caches static files (images, CSS, JavaScript, fonts, PDFs and videos), but not HTML pages. This means that the HTML for a WordPress site is still generated by the hosting provider, whilst the CDN takes over the delivery of the associated files, which are typically much larger.
What are the benefits?
- Faster loading times for remote visitors: larger files are delivered via a shorter route.
- Reduced load on the hosting server: requests served from the cache do not even reach the server, which is particularly useful during sudden traffic spikes.
- Less traffic than the hosting plan includes.
- Security: most CDNs filter out some of the denial-of-service attacks and malicious bots.
If most of your visitors come from the same country and your website is lightweight, the speed improvement will be smaller; however, load reduction and security measures can still be beneficial.
Enabling Cloudflare
Cloudflare’s free plan works with full DNS takeover: you need to point your domain’s name servers to Cloudflare, and from then on, Cloudflare manages your DNS records.
- Sign up with Cloudflare and add your domain.
- Cloudflare reads your existing DNS records. Compare them with your current zone: the A, CNAME, MX and TXT (SPF, DKIM, DMARC) records should all be present.
- For the website records (the domain and
www), the orange cloud (Proxied) should remain selected, whilst for the records relating to email, it should be grey (DNS only). - If DNSSEC was enabled with your previous DNS provider, you must first disable it there.
- Change the name servers at your domain registrar to the two name servers provided by Cloudflare. If your domain is registered with us, you can do this via the client portal under ‘Domain Management’.
- In the SSL/TLS menu, select ‘Full (strict)’ mode (why this one?).
How do you check this?
Open your browser’s developer tools (F12), select an image or CSS file on the Network tab, and view the response headers: server: cloudflare indicates that the request passed through Cloudflare, whilst cf-cache-status: HIT indicates that the file came from the cache. On the first download, it may show MISS, but this will change to HIT after a reload.
Common errors
- Flexible SSL mode: when combined with the hosting account’s HTTPS redirection, this causes an infinite redirection loop.
- Proxied mail records: if the mail server’s address is also placed behind the orange cloud, email clients will be unable to connect.
- Old content following a change: a replaced image or stylesheet may continue to appear in its old form until the cache expires; in this case, clear the cache in the Cloudflare Caching menu.
- IP-based blocks: as the hosting provider sees Cloudflare’s IP addresses behind the CDN, you should configure visitor blocks via the Cloudflare interface.
A detailed guide for WordPress is available on our blog: Using a CDN with WordPress: a step-by-step guide.