Lazy loading YouTube videos doesn't update video thumbnail

When I disable lazy loading YT videos and trigger a HTML rebuild of the particular post, then the thumbnail is refreshed. But when enabling it again and rebuilding the HTML I get to see the old thumbnail again.

Is there a way to clear the tumbnail cache of one video? Or is there a way to set/check the refresh period?

4 Likes

This is more related to YouTube than anything else. When you disable lazy loading, the video iframe gets embeded directly which has direct access to YouTube’s API each time it get loaded.

For lazy loading, we fetch the thumbnail from img.youtube.com/vi/id/maxresdefault.jpg instead. There are multiple image sizes, but YouTube is not very clear on how they update these URLs. We use maxresdefault, which is the largest image they provide and, from my testing, is the one that usually takes the longest to update. In my case I found that thumbnails took anywhere from 1 to 30 minutes to get updated.

And to answer your last question, no, there is no way to set a refresh period. Thumbnail updates are not very frequent, so we don’t have a job that periodically updates them.

2 Likes

The thumbnail is updated on the YouTube side. In new topics it loads with the new one, but in the original topic it keeps reverting to the old one. As if Discourse has a cache. It even happens to this day :slight_smile:

My quick fix now is to disable lazy loading, rebuild the HTML of the topic, it gets the new image, but less efficient. Then I enable lazy loading again and don’t touch the topic anymore.

2 Likes