Speed matters. A slow website loses visitors, hurts SEO, and just feels frustrating. While the Magic Pages websites were already fast, I noticed occasional slower requests when sites were updated frequently or had a low level of visitors.
So, I've spent the last couple of days working on optimizing the CDN infrastructure to make Magic Pages sites load quickly more reliably.
The Problem
Content delivery networks are essentially networks of servers that are distributed all across the world. A copy of your site is stored on these regional servers, so that they are delivered to your users as quickly as possible, without a round trip to Magic Pages' origin server in Germany.
Every time you update or publish a post, the cache on these servers is invalidated on purpose. You want the speed – but you also want your visitors to see the most recent posts.
The problem is what happens right after that invalidation. The first visitor to hit your site has to wait while the CDN fetches fresh content from the origin server. Depending on where they are in the world, this "cold start" could take anywhere from 500ms to over a second.
For sites with steady traffic, this isn't a big deal — the cache stays warm (apart from the poor soul that requests content right after a cache invalidation 🙃). But for newer sites, sites with lower traffic, or right after publishing updates, some visitors were experiencing these slower loads.
The Solution
I've implemented three improvements that work together to eliminate cold starts:
1. Stale-While-Revalidate
Instead of making visitors wait for fresh content, the CDN now serves the previous version immediately while fetching the update in the background. Your visitors get a fast response, and the cache is refreshed for the next request. The content might be a few seconds old, but it loads instantly.
2. Automatic Cache Warming
After every cache invalidation, Magic Pages now automatically requests your homepage, sitemap, and other key pages. By the time a real visitor arrives, the cache is already warm and ready to serve.
Magic Pages is essentially simulating the poor soul that had to wait for the origin server round-trip.
This cache warming happens in the background and does not impact the speed of your site.
3. Optimized Cache Headers
Different types of content now get different caching rules:
- HTML pages are always checked for freshness (so updates appear immediately)
- Static assets like CSS, JavaScript, and images are cached aggressively (Ghost's versioned URLs ensure you still get updates after theme changes)
Before, these were treated the same, invalidating versioned assets that don't need invalidation.
The Result
The results are consistent fast responses, when the CDN is activated (which is the case on the Pro plan). Here's a current benchmark on a site using Magic Pages's Alpine theme, right after publishing a new post:
| Location | Response Time |
|---|---|
| Frankfurt | 108ms |
| Amsterdam | 141ms |
| London | 188ms |
| New York | 211ms |
| San Francisco | 209ms |
| Singapore | 74ms |
| Sydney | 280ms |
| Bangalore | 402ms |
These response times include DNS lookup, TLS handshake, and full HTML delivery. Not just time-to-first-byte. And crucially, they're consistent. No matter if somebody is your first
visitor after an update or the thousandth, they get the same fast experience now.