What is a CDN?

A content delivery network keeps copies of your site’s files in data centers around the world, so visitors download them from somewhere close.

1–2 minutes
Aerial view of a data center campus

A content delivery network (CDN) is a network of servers spread across many cities. It keeps copies of your site’s files, such as images, stylesheets, scripts and sometimes whole pages, and serves each visitor from the location nearest to them.

A CDN makes a site faster for distant visitors and takes load off your own server. Your server stays the origin, the source of truth; the CDN’s edge servers hold cached copies.

Why distance matters

Data travels fast, but not instantly. A request from Sydney to a server in London and back takes around 250 milliseconds before any work is done, and a page needs many requests. Serving from an edge server in Sydney cuts that to a few milliseconds.

How it works

  1. You point your domain (or a subdomain) at the CDN, usually by changing DNS.
  2. A visitor’s request goes to the nearest edge server.
  3. If the edge has a fresh copy, it answers straight away (a cache hit).
  4. If not (a cache miss), it fetches the file from your origin, keeps a copy, and answers.

How long copies are kept is set by cache headers your server sends, or by rules in the CDN.

What else CDNs usually do

  • Absorb traffic floods and many denial-of-service attacks.
  • Handle HTTPS at the edge.
  • Compress files and convert images to modern formats.
  • Keep serving cached pages for a while if your origin goes down.

Things to know

  • Changes take a moment. After updating a file, purge it from the CDN cache, or use versioned file names.
  • Logged-in pages should not be cached. Shops, dashboards and account pages must pass straight through to the origin.
  • Your server sees the CDN’s address. Configure it to read the real visitor IP from a header such as X-Forwarded-For, or logs and rate limits will treat everyone as one visitor.

Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.