Front End · JavaScript · Caching

The Thumbnails That Vanished for a Month

Product page thumbnails kept disappearing, and our monitoring had been complaining for weeks. The template looked broken, so I fixed the template. That wasn't it. The real problem was a script file that was quietly returning a 404.

A gallery with no thumbnails

On one brand's product pages, the image gallery is supposed to show a big main photo with a row of clickable thumbnails underneath. For weeks, the thumbnails just weren't there, especially right after a server restart. Our page monitor had been flagging it for about a month.

The main image loaded. The page didn't throw anything obvious. The thumbnails were simply missing.

The convincing wrong answer

I opened the gallery's template and found what looked like a smoking gun: the thumbnail image tags were commented out, and the loop was pointing at the wrong item. Two bugs, right there in the code. I fixed both.

Then I compared it with our QA environment, where the gallery worked fine, and realized the template was never supposed to draw the thumbnails itself. A JavaScript carousel builds them in the browser from data on the page. Those "bugs" were by design. So I put the template back the way it was.

Lesson one, learned the fun way: code that looks wrong isn't always the bug. Check how it's supposed to work before you fix it.

Follow the script

If the carousel builds the thumbnails, the real question was: is the carousel even running? The browser's network tab answered that. The site's main scripts bundle was returning a 404.

The CMS adds a timestamp to each bundle's URL so browsers grab fresh copies after a change. The cached page HTML was asking for the scripts bundle using the styles bundle's timestamp. Same date stamp, wrong file. That URL didn't exist, so the scripts never loaded, the carousel never started, and the thumbnails never appeared.

Cached page asks for the scripts bundle
        ↓
...using the styles bundle's timestamp
        ↓
404: no scripts → carousel never starts
        ↓
No thumbnails (and no error on the page)

The fix

I refreshed the scripts bundle in the CMS so it got a brand-new timestamp, published it, and cleared that brand's page cache so the HTML would be rebuilt with the right URL. Then I confirmed the timestamp the page asked for matched the file that actually existed.

The bundle loaded, the carousel started, and the thumbnails came back.

What I took away

  • Check how a component is supposed to work before "fixing" code that looks wrong.
  • When something built by JavaScript is missing, first check whether the JavaScript loaded at all.
  • The network tab is often faster than reading code.
  • Caches can keep serving a broken reference long after the original cause is gone.
  • Compare with a working environment. The difference is usually the answer.