How I Fixed Stale HTML and Cache Problems
When the new page appears for one refresh and disappears on the next, the cache is telling you something.
By Shadorux · · 7 min read · Caching · Debugging
One of the most confusing problems I ran into was seeing an updated page after a hard refresh, only for an older version to come back later. The code was updated, the deployment looked successful, and the browser still seemed to be haunted by an earlier copy.
There can be more than one cache
A browser can cache the HTML. A CDN can cache the response at the edge. A service worker or hosting layer can add another copy. A hard refresh only deals with part of that chain, so it is not proof that the live origin is serving the newest document.
The first useful comparison was to check the actual response and its headers, then compare the page source with the browser's live DOM. That separated “the server sent old HTML” from “JavaScript changed the page after it loaded.”
HTML and assets need different rules
HTML is the document that changes most often, so I configured the CDN to bypass its cache for the site's HTML routes. Static assets can still be cached efficiently, but only when their URLs change whenever their contents change.
/js/westopolis-explorer.js?v=20260911-3The query version is a small but important signal. When the Explorer script changed, changing its version made browsers and edge caches request the new file instead of trusting an older copy.
Targeted purges beat guessing
After changing the cache behavior, I purged the affected page URLs and the Explorer script directly. That cleared the copies most likely to be stale without treating every asset on the site as disposable.
Cache checkpointIf a hard refresh briefly shows the right page, compare the response headers and the nested script URLs before changing the layout. The wrapper may be new while the script it loads is old.
What fixed the recurring problem
- HTML routes were excluded from edge caching.
- Versioned URLs were used for changing JavaScript and CSS.
- Specific URLs were purged after the rule changed.
- The live page was checked again after a hard refresh.
The important fix was not refreshing harder. It was giving HTML and immutable-looking assets different cache policies, then verifying the actual response that visitors receive.