Caching and CDNs
A CDN is often sold as the fix for a slow site. Frequently the fix is three response headers you already control.
Headers first
Nothing caches anything unless you say so.
- Fingerprinted assets —
app.a1b2c3.css— getCache-Control: public, max-age=31536000, immutable. A year, because a new build gets a new name. - Images and fonts that rarely change: weeks to months.
- HTML: short, or
no-cachewith anETagso clients revalidate cheaply. - Anything personal:
Cache-Control: private, no-store. Caching a logged-in page publicly serves one user's data to another.
Then check what you actually send:
curl -sI https://example.com/app.css | grep -i cache
Your own edge with nginx
Before buying anything, cache on the machine you already rent:
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=edge:100m
max_size=20g inactive=7d;
and in the location: proxy_cache edge; with
proxy_cache_use_stale updating error timeout; so a slow backend does not
mean a slow site. Add proxy_cache_lock on; to stop a thundering herd when
a popular object expires.
On a machine with plenty of memory and an unmetered port, this handles very large volumes and costs nothing per gigabyte.
When a CDN genuinely helps
- Your users are far away. Physics: a request from Sydney to Amsterdam is about 280 ms round trip no matter how fast your server is.
- Very spiky traffic you do not want to provision for.
- You want absorption of attacks at the application layer, beyond the volumetric DDoS filtering we already provide.
When it does not
- Your users are European. From Amsterdam you are within 10–35 ms of most of them — see why Amsterdam. A CDN adds a hop and saves little.
- Your content is dynamic and personal. There is nothing to cache.
- Your site is slow because of the database. A CDN will not touch that; see diagnosing a slow server.
Egress is the quiet argument
CDNs are usually priced per gigabyte delivered. On an unmetered port, delivering from your own machine has a fixed monthly cost no matter how busy the month is. For high-volume delivery that difference is frequently the largest number in the comparison — see streaming and high-bandwidth delivery.
Measure before and after
Take a real figure first — time to first byte and full load, from where your users are. Then change one thing. “It feels faster” is how people end up paying monthly for a layer that made no difference.
Still stuck? Mail support@novogara.com — an engineer answers, at any hour. Back to the knowledge base