· 2 min read
A YouTube video without YouTube on the page
A new fenced-block component, yt : src (any YouTube link shape), title, an optional thumbnail (a file next to the post) and caption. It renders a card with…
What we did
- A new fenced-block component,
```yt:src(any YouTube link shape),title, an optionalthumbnail(a file next to the post) andcaption. It renders a card with the picture, the title and "opens in a new tab", as a plain link to youtube.com. - Nothing loads from Google until a reader clicks: no player, no scripts, no cookies, and the thumbnail is our own copy (one from
i.ytimg.comwould be a request to Google too). Checked: loading the post makes no request outside the site. render()inblocks.tsnow gets the post's file name, so the card's text follows its language (<slug>.es.mdis Spanish), like callout titles.enhance-media.tsnow accepts an explicitalt="": markdown can't write one (mdsvex leavesaltout), so it only comes from a block marking its picture as decorative.- First used in the UTF-8 draft, for Dylan Beattie's talk "Plain Text".
What I learned
- An embedded YouTube player loads Google's scripts on every page view, watched or not. A link with a picture costs nothing until it's used.
rel="noreferrer"also keeps our page's address from YouTube;noopeneris the default fortarget="_blank"now, but writing it costs nothing.- Opening a new tab without warning surprises people, so the card says it does.
Links
- MDN:
rel=noreferrer - YouTube's oEmbed endpoint (where a video's title and thumbnail can be looked up)
Next
- The cursors and selection tool.