You Fixed It but the Screen Has Not Changed — How Caching Works

This article is part of the IT Foundations course, which builds up from scratch the practical IT knowledge you need at a minimum for programming and vibe coding.
When a fix does not show, an old copy is still sitting somewhere. Diagrams cover how to narrow it down across the browser, the CDN, and the public server, and how to make a change reach users for certain.

This article covers the situation where you fixed it but the screen has not changed.

You fixed the code and deployed it, but when you open the page, it is still the old version.

The cause is usually not the code, but an old copy still sitting somewhere.

When a fix does not show, an old copy is somewhere
Fixed, butnothing changedYour own browserThe delivery layerThe public serverReloadHave it clearedDeploy againOnly youEveryoneEveryone
The left is the symptom. An old copy is left in one of the three places in the middle, and the right is how to clear it. The far right is who sees the old version in that case.

Whether only you see the old version or everyone does tells you where it is left.

What a cache is — returning a kept copy instead of fetching it again

A cache — which keeps something fetched once nearby and, from then on, returns that instead of fetching it again — exists so that the same thing is not fetched over and over.

Something fetched once is kept at hand, and from the second time on, that is what is used.

In exchange for speed, there is a stretch of time when it does not notice that something has been updated.

The length of that keeping is the lifetime (max-age) — the time a kept copy may be used without fetching again.

Until the lifetime expires, the local copy keeps being used even if you fix the server.

The less something changes, as with images and CSS, the longer the setting tends to be.

The same fix gives a different result inside or outside the lifetime
Fix app.csson the serverOpen insidethe lifetimeUse the localcopy as isThe fix doesnot showOpen after thelifetime expiresFetch againfrom the serverThe fixshows
The left is the moment you fixed it on the server. The upper and lower branches differ by whether the screen was opened inside or outside the lifetime, and what comes out changes.

A fix does not show while the lifetime has not expired.

A cache returns an old copy

A cache keeps something fetched once nearby and returns that from then on.

It is faster because it does not fetch every time, but it does not notice when the server side is updated in the meantime, so you get a fix that does not show.

The three places a copy sits — in your browser, in the delivery path, and in the server

A copy sits in more than one place.

There are three places, nested, running from closest to the user outward.

The innermost one, the copy your own browser holds, is the browser cache.

The three places an old copy can be left
The places passed through before the screen appears
1. In the user's browser (browser cache)
  • Left only on that person's device
  • Reload and it can be fetched again
  • This is it when only you see the old version
2. In the delivery layer (CDN)
  • A copy placed close to the user
  • Everyone sees the same old version
  • Stays until you have it cleared
3. In the public server
  • The build output you placed there
  • If the deploy failed, it is still the old one
  • If this is old, everyone sees the old version
The further out, the more distant the place. Check from the inside, closest to the user, outward, and you can tell where it stops.

The second one, the CDN — which places copies close to users and delivers from there — is built into many deploy targets from the start.

These three places differ in how you clear them and in how far the effect reaches.

Having the CDN's copy cleared is a purge — deleting the copy the delivery layer holds and making it fetch again.

Some setups purge automatically on every deploy.

What a forced reload is

With an ordinary reload, the local copy is sometimes used as is.

The action that forces a re-fetch is called a hard reload (a forced reload), and if you only want to check, opening the page in a window that keeps no history does the same thing.

Narrow it down by whether only you see the old version or everyone does

Rather than trying the three places from the top down, checking the range first finishes faster.

What you look at is whether people other than you also see the old version.

Who sees the old version decides where the cause is
Do others seethe old one tooOnly you see itEveryone sees itReloadat your endCheck the CDNand the output
The left is what to check. If only you see the old version, it is at hand; if everyone does, it is further out. The right is the action to take next.

If it is only you, the cause is nowhere but inside your own browser.

If other people see the old version too, no amount of reloading at your end changes it.

The bottom one is the case where the new files never reached the public server in the first place.

If the build failed, what is published is still the previous output.

A reload that fixes it is not necessarily a solution

Reloading at your end gives you the new version, but that only swapped the copy on your one machine.

On users' devices, the old copy stays until the lifetime expires.

Change the file name and the old copy stops being used

Instead of going around clearing copies, there is a way to keep the old copy from being used at all.

It is to change the file name together with the contents.

Replace under the same name, or change the name too
Fix the contentsof app.jsPlace again underthe same nameChange the nameapp.a1b2.jsThe local copyis usedNot at hand,so it fetches
The top is when only the contents change under the same name, and the local copy is used as is. The bottom changes the name, so it is treated as something not at hand and fetched.

Replace part of the file name with characters calculated from the contents, and the name changes every time the contents change.

If the name is different, the local copy is a different file, so it is not used.

This naming work is done automatically at build time.

You do not need to think up names yourself.

FileHow it is namedHow to set the lifetime
index.htmlDoes not changeMake it short
app.a1b2.jsThe name changes when the contents changeCan be long
Assets such as imagesThe name changes when the contents changeCan be long

The entry point, index.html, is the one file whose name cannot change, so you keep its lifetime short.

Once the names of the files it loads are new, everything from there on arrives new automatically.

Once it is found at an earlier point, it does not go any further to fetch.

So if even one place still holds an old copy, the new version does not arrive.

Changing the name is surer than going around clearing copies

If the file name changes when the contents change, the local copy is a different file and is not used.

The build does this naming automatically, so you only keep the lifetime short for the entry file, whose name cannot change.

QUIZ

Knowledge Check

Answer each question one by one.

Q1You deployed again, but your own browser still shows the old screen. On another device it is new. Where is the cause?

Q2What does the browser do when the cache lifetime has not expired?

Q3What happens when you set things up so that the file name changes whenever the contents change?