Hosting, CDN and caching: the invisible foundation of a fast website
How infrastructure sets your response time before any code optimization.
Before thinking about images, fonts or scripts, there is a more basic question: how long does it take for the first byte to reach the browser? That metric, TTFB, depends almost entirely on infrastructure.
Shared hosting, VPS and edge platforms
On shared hosting, hundreds of websites share the same server. The price is low, but response time varies depending on your neighbors.
A VPS gives you dedicated resources and control, and in exchange someone has to handle updates and security.
Edge platforms, like the ones that serve static websites, distribute files across dozens of regions and remove almost all server maintenance.
What a CDN does
A CDN keeps copies of your content on servers around the world and serves each visitor from the nearest point. The gains are threefold: lower latency, less load on the origin and basic protection against spikes and attacks.
Layered caching
Think of four levels:
- Browser: files with a hash in their name can be cached for a year.
- CDN: keeps HTML and assets at the edge.
- Application: avoids repeating the same queries and calculations.
- Database: only comes into play when the other three miss.
The golden rule is simple: whatever doesn’t change often should have a long cache lifetime, and the file name should change when the content changes.
Common mistakes
- Caching turned off for fear of showing stale content.
- Dynamic HTML on pages that could be static.
- Images served without compression or modern formats.
- No HTTP/2 or HTTP/3 at the origin.
What it’s worth
Cutting TTFB from 800 ms to 100 ms improves LCP by almost the same proportion, without touching a single line of design. It is the most cost-effective optimization there is, and almost nobody looks at it.