Get the latest tech news

Fighting with YouTube to show a preview image


TLDR: Click here for code to implement a lightweight, resilient clickable YouTube preview. YouTube videos are expensive to load on a web page. This compounds if you want your page to display many v…

TLDR: Click here for code to implement a lightweight, resilient clickable YouTube preview. Of course, YouTube does a decent job of caching these resources, but your browser is still doing all this work, creating another complete page context per video, executing all it’s JavaScript etc. Instead of an onerror, add an onload handler to the<img /> element, and check the size of the image.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of YouTube

YouTube

Photo of preview image

preview image

Related news:

News photo

Report: Apple Testing Revamped Siri With Apps Like Uber and YouTube

News photo

Best VPNs for YouTube in 2025: 5 providers for unblocking content

News photo

Call to vet YouTube ads like regular TV to stop scams