When Your CDN Won't Let You Ship a Bug Fix
A diagram kept showing the wrong thing after every fix landed - not because the build was wrong, but because an edge cache was confidently, correctly serving a stale answer.
Table of contents
A diagram embedded in a blog post kept showing the wrong thing after every fix landed. The build was correct, the deployed files were correct, and the browser still rendered a stale version - because somewhere between origin and the reader sat a cache that had decided it already knew the right answer.
How one uploaded image ends up wedged behind an edge cache
The diagram lived as an uploaded media asset in the CMS, served at a fixed URL under /uploads/.... Every time the diagram needed a fix - a wrong arrow, a label that didn't match the current pipeline - the file got replaced at that same URL. That's normally fine. It stopped being fine once Cloudflare sat in front of it: the response carried cf-cache-status: HIT against a Last-Modified timestamp from *before* the latest fix, comfortably inside its four-hour max-age. The cache wasn't broken. It was doing exactly what a cache does - it just didn't know the file underneath its key had changed, because nothing in the request told it to check.
Why fighting the cache is the wrong fight here
The obvious fixes are all cache-control tuning: shorter max-age, a cache-busting query string, an explicit purge call after every upload. Every one of those works right up until the next time the same asset gets replaced in place and someone forgets the extra step - and a purge API is one more moving part to get right, for a problem that only exists because the file is cacheable at a stable URL in the first place.
The actual fix available here was better than any of those: the whole site already ships through a normal git-to-build-to-deploy pipeline. If the diagram doesn't need to be a separately-fetched asset at all, there's no cache key for an edge cache to get stale on.
Moving the diagram into the page bundle instead
The fix replaced the uploaded SVG with an inline SVG React component, rendered directly as part of the page's own markup. The CMS still keeps the original image block in the post body - alt text and all - as a non-visual fallback and a marker of where the diagram belongs; a small lookup table in the rendering component recognizes that specific image reference and swaps in the real inline component instead of an <img> tag pointing at the uploaded file. Ship a new build, and the diagram is part of the HTML the server already generates fresh every time - no separately-cacheable URL left for anything to go stale behind.
The build was verified by checking the rendered page source directly: the diagram now shows up as real inline <svg> markup, not a reference to an uploaded file at all.
The tradeoff that's still there
The fix isn't free of fragility, just a different kind. The lookup table that decides "render this image block as the inline component instead" matches on a substring of the uploaded asset's filename - which is itself derived from that specific upload's content hash. Re-upload the same diagram in the CMS later, even keeping the same filename and caption, and the platform mints a new hash; the substring match silently stops firing, and the page quietly falls back to rendering the original uploaded asset again - the exact cache-prone path this fix existed to avoid, with no error anywhere to flag that it happened. That's a known, tracked loose end rather than a surprise: a more stable match key (something in the alt text, or an explicit marker in the caption) is the obvious next step, just not this one's.
The actual lesson
A CDN cache (Cloudflare, in this case) that's doing its job correctly isn't the bug - treating a piece of content as cacheable when it's small, versioned, and already flows through a build pipeline is. The fastest way to stop fighting a cache isn't a smarter purge strategy; it's noticing when the thing being cached didn't need its own URL in the first place.