How does a content delivery network work?
A CDN is a set of interconnected servers spread across many geographic locations, known as points of presence (PoPs) [1]. The first time someone in a region requests a static file, the origin server, which holds the original content, answers and a copy is placed in the nearest PoP. Later requests from that area are served from that cache [1]. For dynamic content that cannot be cached, the CDN still forwards the request to the origin, but over an already-open, optimised connection [1].
What does a CDN buy you, and what does it cost?
AWS lists faster page loads, lower bandwidth bills because the origin serves less data, better availability during traffic spikes or server failures, and some protection against DDoS attacks because traffic is spread across intermediary servers [1]. MDN adds the simple physics: geographic distance adds latency, so a server near the user helps [2].
There are trade-offs. A CDN is a third-party dependency, so if it goes down, is blocked in a region or shuts down, your site breaks with it. A compromised CDN can also serve malicious files to your users, which is why countermeasures such as Subresource Integrity (SRI) exist [2].
Where are CDNs used?
The classic case is serving the CSS and JavaScript files of libraries such as Bootstrap or jQuery from a CDN. Whole static sites built only from HTML, CSS and JavaScript can be served from one too [2]. At the larger end, AWS says the streaming service Hulu uses Amazon CloudFront to consistently stream more than 20 GBps to its customers [1].