Skip to content

Everything for WordPress, web development — and beyond

Lightweight facade for YouTube and Vimeo

Lightweight YouTube and Vimeo embeds: facade generator

Paste the links to the videos and get a ready-made block that shows a preview and loads the player only after a click. Zero external libraries: everything needed is inside the generated code.

One per line. YouTube: watch?v=, youtu.be, /embed/, /shorts/, youtube-nocookie.com. Vimeo: vimeo.com/ID, player.vimeo.com/video/ID, private vimeo.com/ID/HASH. The timestamp ?t= / &start= is carried over into the facade. Optional details separated by a vertical bar: URL | Title | Thumbnail URL.
hqdefault exists for every video. maxresdefault exists only where the original was uploaded in 720p or higher — otherwise the image simply will not load and the viewer sees an empty rectangle.
Shared by all videos. A title after the dash in the line takes priority. The caption also goes into the button's aria-label and the iframe's title.
Vimeo has no predictable frame address like YouTube's i.ytimg.com: only the oEmbed API returns it, and we cannot make a request to it — the tool works offline. So upload the frame to the site's media library and paste the link. Without it you get a gradient placeholder with a play button.
Behaviour of the generated block
Paste at least one link to see the facade.

The code is assembled in your browser. Neither the generated block nor the preview itself makes any external request — the images from i.ytimg.com in the preview are shown as addresses, not loaded.

A single embedded video costs over a megabyte before the first click

A standard YouTube iframe loads about 1.3 MB in a couple of dozen requests to seven third-party domains — before the visitor has even decided to watch the video. On a page with three videos that is three times as much, and it is almost always what ruins the speed scores on mobile. The facade solves the problem head-on: at first only a preview image with a play button is shown, and the real player is inserted at the moment of the click. Before the click the page weighs an order of magnitude less. There is a popular library for this, but every guide advises loading it from someone else's CDN — that is, removing one external request and adding another. Here the generated code is completely self-contained: the styles and the script sit inside the block. There is a further effect, on privacy. A standard iframe sets tracking cookies before anything is even watched. The youtube-nocookie.com domain postpones that until playback starts, and the facade until the click. For sites aimed at a European audience this bears directly on cookie-consent requirements.

Frequently asked questions