Skip to content
Book a call (opens Calendly in a new tab)
Build notes · 2 min read

I replaced the screenshots and still saw the old ones

I recaptured a case study's screenshots and deployed, but the old ones kept showing. The server had the new files. Two caches were serving the old ones, and here's how I proved it and fixed it.

On this page
  1. First: is it the deploy or the cache?
  2. Two caches, stacked
  3. The fix: change the URL
  4. What I'd do differently

When Mukto Provat went live, I recaptured its screenshots from the real site, replaced four files, pushed, and waited for the deploy. Then I reloaded my own home page and saw the old pictures.

The files had the same names as before. Nothing else had changed. Here's how I worked out what was going on.

First: is it the deploy or the cache?

The question that splits the problem in two is whether the server has the new file. A browser can't answer that, because the browser is the thing in doubt. curl can:

curl -s https://onenazmul.dev/images/work/mukto-provat/full.webp | wc -c
wc -c < public/images/work/mukto-provat/full.webp

Same byte count on the server and on my disk, for all five files. The deploy was fine. Something between the server and my screen was holding the old copy.

Two caches, stacked

The HTTP cache. The host sends this header for images:

cache-control: public, max-age=604800

That's seven days. A browser that has seen the file won't ask for it again for a week.

The service worker. This site is installable, and its service worker keeps images so repeat visits are fast. The rule is short:

{
  matcher: ({ request, sameOrigin }) => sameOrigin && request.destination === "image",
  handler: new CacheFirst({
    cacheName: "images",
    plugins: [new ExpirationPlugin({ maxEntries: 64, maxAgeSeconds: 30 * 24 * 60 * 60 })],
  }),
},

CacheFirst means: if I have it, use it, and don't check the network. Cached copies last up to 30 days. Once a visitor has the old image, no deploy can reach them.

Both rules are doing their job. Neither can tell that a file with the same name now holds a different picture. That's the real problem: a URL is the cache's only way to know what a file is.

The fix: change the URL

I didn't want to loosen the caching. Fast repeat visits are the point of it, and a rule that bypasses the cache for images would throw that away. Instead the new screenshots went into a new folder:

/images/work/mukto-provat/full.webp     →   /images/work/mukto-provat/v2/full.webp

A URL nobody's cache has ever seen is fetched fresh, and from then on it's cached like any other. The case study's frontmatter changed in two lines:

heroImage: "/images/work/mukto-provat/v2/full.webp"
mobileImage: "/images/work/mukto-provat/v2/mobile.webp"

The cards' small preview images are found by swapping full.webp for poster.webp in that path, so keeping the whole set in one folder meant nothing else needed touching. The old files are simply no longer referenced.

What I'd do differently

  • Version the path from the start for images that might ever be replaced, even if it's just v1. It costs nothing and removes the whole problem.
  • Fingerprint the filenames (a hash in the name) if you have many images. Next.js does it for its own scripts and styles; files in public/ don't get it, so it's on you.
  • Test twice. A private window shows what a new visitor gets. Your normal window shows what a returning visitor gets, and that's the one that breaks.
  • Don't trust your own browser to tell you a deploy worked. Ask the server with curl.

Next time it's v3.