How a CDN works
Without a CDN (content delivery network), every visitor downloads all images, styles and scripts from the single server where your hosting is. If the server is in Germany and the visitor is in Slovakia, that is fine. But if a customer is shopping from Canada, the data travels halfway around the world and every file is delayed.
A CDN copies the files from your server to dozens or hundreds of servers in different countries. The visitor then gets them from the nearest one. Your server handles far fewer requests, because the network takes over most of the work.
Many CDN services, such as Cloudflare, do more than that: they cache entire pages, resize images, filter suspicious traffic and protect the site from attacks designed to overwhelm it.
When a CDN helps and when it does not
It makes the biggest difference if you have visitors from several countries, lots of images or videos, or occasional sharp traffic spikes. An online shop selling to the Czech Republic, Austria and Hungary will get more out of a CDN than a local tradesman whose customers all live in one district.
Even for a small website a CDN makes sense, for protection and to take load off the server. But do not expect it to fix a slow site. If the server takes several seconds to build a page, a CDN speeds up image delivery, but not the wait for the page itself.
A real example
A Slovak online shop selling handmade jewellery also sells to Germany and the UK. Its product photos are large and detailed. Since a CDN was set up, images are delivered to customers abroad from their own country, and the server in Slovakia copes with the pre-Christmas peak without slowing down. The CDN also filters out some of the bots that were trying passwords on the admin login.
What to watch out for
- DNS settings. With some CDNs you move your domain management to them. Do it carefully so you do not break your email.
- Dynamic pages. The basket, checkout and login must not be stored in the CDN cache.
- Updates. After changing an image or a stylesheet, the CDN cache needs clearing, otherwise visitors will see the old version.
How I handle it at 5pixel
I set up a CDN when speeding up websites where it makes sense, most often Cloudflare combined with server-side caching. But first I check whether the bottleneck is the server or the theme itself. A CDN can also be switched on later, most easily during a website migration to new hosting.