CDN (content delivery network)
A CDN is a network of servers spread across many locations that store copies of a site's files and serve each visitor from a nearby one. It cuts the physical distance a request travels, which is the part of page speed that no amount of code optimisation can fix.
Distance is latency
A request from Stockholm to a server in Virginia crosses the Atlantic twice before the first byte comes back, and connection setup means several round trips. That is 100 milliseconds or more of unavoidable delay, repeated for every uncached resource. Serving the same file from a node in Stockholm removes it.
The second benefit is capacity. A traffic spike is absorbed by hundreds of edge nodes rather than by your origin server, and files served from cache never reach your infrastructure at all. This is why static hosting on a CDN — Firebase Hosting, Cloudflare, Netlify — is both faster and cheaper than a single virtual machine, and why statically generated sites are such a natural fit.
What a CDN can and cannot cache
Cacheable, and where the win is largest: images, fonts, CSS, JavaScript bundles, and prerendered HTML pages that are the same for everyone.
Not cacheable in any useful way: personalised HTML, and every API response that reflects one user's data. This is the misconception worth stating plainly — a CDN does not make a slow database or a slow API faster. If your app spends 800 milliseconds waiting for a query, putting a CDN in front changes almost nothing, because that response cannot be reused for the next visitor. It shortens the transport, not the work.
Cache control is the part that bites
Two headers decide behaviour: Cache-Control sets how long a file may be reused, and ETag lets a browser revalidate cheaply. The standard pattern is to give hashed asset filenames a very long cache lifetime and HTML a short one, so a deploy changes the filenames and old files simply stop being requested.
Get it backwards — a long cache on HTML — and users keep seeing yesterday's page long after you deployed. Purging the edge cache fixes the CDN's copy but not the copy already sitting in each browser, which is why the filename-hash approach is preferred over relying on purges.
Frequently asked questions
Will a CDN speed up my app if the slow part is the database?
No. A CDN caches and delivers files that are identical for many visitors. A database response that reflects one user’s data cannot be reused, so it goes to the origin every time. Fix the query, add indexes, or cache the result on the server instead.
Build it yourself
NorthernGo turns a plain-text description into a working web app with a database, login and a live URL. Local AI generation runs on your own GPU, is unlimited, and is free on every plan.