Why They Tell You to "Clear Your Cache" — Caching and CDNs
When you tell a developer that the screen looks wrong or that a change isn’t showing up, there’s a good chance the same answer comes back: “Try clearing your cache.” Or “Try a hard refresh.” You hear it often when you’re sure something was fixed but your screen still shows the old version, or when yours looks fine but only a colleague sees a broken screen.
What exactly is this cache, and why does being told to clear it come up so often? In this post, I’ll unpack, without any code, what a cache is and how its close relative, the CDN, makes the web fast.
A cache keeps frequently used things close by #
The idea behind a cache is simple: instead of fetching frequently used things from far away every time, keep a copy close by and pull from it.
It’s like keeping a book you read often on your desk instead of going all the way to the library. A book on your desk is within arm’s reach, so you save the time of going back and forth to the library each time. Computers work the same way. They keep data fetched once somewhere close, and the next time the same thing is needed, they use that copy right away instead of going far. This way, the same task gets done much faster.
This idea is used all over the web. The one we run into most often is the browser cache.
The browser cache is a copy left on your device #
Opening a single website doesn’t just bring text. Images, the design files that style the screen, and the files that carry behavior all come down together. But these don’t change much each time you open the page. So the browser stores files it received once on your device, and the next time you open the same site, it uses the stored copy instead of fetching them anew. A site loading faster from the second visit on is thanks to this.
The problem starts here. Even when a developer swaps in a new design file and deploys it, your browser may show the old copy as is, figuring “I already have this one.” That’s how you end up with only your screen showing the old version even though something was supposedly fixed. In this case, “try clearing your cache” means to throw away the stored old copy and fetch it fresh. A hard refresh does the same thing: it ignores the stored copy and fetches the latest file from the server again.
A CDN is a network of copy warehouses scattered worldwide #
Taking the cache idea to a larger scale gives you the CDN. In full, it’s called a content delivery network.
Say a service’s server is in Korea. When a user on the other side of the world opens this site, it’s slow because the data has to travel a long distance back and forth. A CDN solves this with copies. It copies frequently used things, like images and design files, to many places around the world in advance, and when a user connects, it delivers from the location closest to that person.
It’s like a convenience store chain spread across the country. Instead of going all the way to the headquarters warehouse to buy something, you get the same item at the store right by your house. Receiving it from a nearby place rather than traveling to and from a distant headquarters is much faster, and it also cuts down on crowds rushing the headquarters all at once. A CDN is a mechanism that gives users speed and relieves the server of load.
A cache is fast but can show you old content #
A cache is a tool for speed, but in exchange it carries the risk of showing old content. As long as you use a copy, if the original changes but the copy stays the same, the old version shows. The “fixed it but it isn’t changing” problem we saw earlier is exactly this price.
That’s why developers use several methods when they have to make sure new content shows. They might give a file a slightly different name each time it changes so the browser treats it as a file it’s seeing for the first time and fetches it anew, or they command the CDN to throw away all the old copies scattered across it at once. Throwing away old copies like this is called cache invalidation. When deployed content doesn’t show up to users right away and the development team says “it’s because of the cache,” this is the situation.
Why this makes work easier for non-developers #
- The “I can see it but my colleague can’t” situation makes sense. It happens because each browser has a different cached copy. Clear the cache and look again, and you usually end up with the same screen.
- You don’t panic right after a deployment. New content not showing up immediately doesn’t always mean a bad deployment. The cache may just be showing the old copy a little longer.
- Verify with the cache cleared. When you check a freshly changed screen, clearing the cache or doing a hard refresh to see the latest state before judging reduces the chance of being fooled by an old copy.
Wrapping up #
A cache is the idea of keeping frequently used things close by to boost speed, and a CDN is a mechanism that scatters those copies around the world to deliver them fast to anyone. Both are solid tools for making the web fast, but they carry the price that, as much as you use copies, they can show old content. Now you have a feel for why “try clearing your cache” comes up so often.
If you’d like to know more about how servers and deployment work, read Servers, the Cloud, and Deployment; if you’re curious about the cloud you rent those servers from, read The Cloud Is Really Just Someone Else’s Computer.