CDN
Content Delivery Network
In short
A CDN is a network of servers spread around the world that stores copies of website content and delivers it to each user from the nearest location.
What is a CDN?
A CDN, or content delivery network, is a group of servers in many locations, often called edge servers or points of presence, that deliver web content to users. Instead of every visitor loading files from one origin server, each visitor gets them from a nearby CDN server, which makes pages load faster.
CDNs work by caching. The first time someone in a region requests a file, such as an image, a JavaScript bundle, or a video segment, the edge server fetches it from the origin and keeps a copy, and later visitors nearby receive that cached copy directly. HTTP headers such as Cache-Control tell the CDN how long each file may be stored.
Think of a CDN like a chain of local warehouses: instead of shipping every order from one central factory, popular products are stocked close to customers so deliveries arrive faster. Beyond speed, CDNs reduce load on the origin server, absorb traffic spikes, help protect against DDoS attacks, and handle HTTPS connections close to the user.
A CDN does not replace your web server or hosting; the origin still holds the original content and runs your application logic. Many modern CDNs also offer edge computing, which runs small pieces of code on the edge servers themselves, blurring the line between a CDN and a serverless platform.
At a glance
Key takeaways
- A CDN serves content from servers close to each user.
- It works by caching copies of files from the origin server.
- CDNs reduce latency, lower origin load, and help absorb traffic spikes and attacks.
Cache-Controlheaders control how long content is cached.- Many CDNs can also run code at the edge.
Example
# Show only the response headers for a file served through a CDN
curl -I https://cdn.example.com/images/logo.png
# Typical headers in the response:
# cache-control: public, max-age=31536000, immutable (cache for up to a year)
# age: 3600 (seconds spent in the cache)
# x-cache: HIT (served by the edge, not the origin)Readers ask
Do I need a CDN for my website?
A CDN helps most when your visitors are spread across different regions or your site serves many images, scripts, or videos. Many hosting platforms include a CDN automatically, so you may already be using one.
What is the difference between a CDN and web hosting?
Web hosting stores your site and runs its application code on an origin server. A CDN sits in front of that server and delivers cached copies of the content from locations close to your users.
What is a cache hit in a CDN?
A cache hit means the CDN edge server already had a stored copy of the requested file and served it directly. A cache miss means it had to fetch the file from the origin server first.
See also
- HTTPWeb Development, p. 19HTTP is the protocol that browsers, apps, and servers use to exchange web pages and data through a simple cycle of requests and responses.
- HTTPSSecurity, p. 17HTTPS is the secure version of HTTP that encrypts traffic between a browser and a website with TLS, protecting data from eavesdropping and tampering.
- ServerlessDevOps & Cloud, p. 47Serverless is a cloud model in which the provider runs your code on demand, manages all the servers, scales automatically, and bills only for actual use.
- DevOpsDevOps & Cloud, p. 14DevOps is a set of practices and a culture that brings software development and IT operations together to deliver software faster and more reliably.
- SPAWeb Development, p. 41An SPA is a web application that loads a single HTML page and then updates content with JavaScript, so moving between views does not reload the page.
- SSRWeb Development, p. 43SSR is a technique where the server builds the full HTML for a page on each request, so users and search engines receive ready-to-read content immediately.
Spotted a mistake or something missing on this page?Suggest an edit