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.
Or read this on Hacker News