Skip to content

Commit 7f8a321

Browse files
authored
feat(params) Allow for prefetching url (#70)
* feat(params) Allow for prefetching url Adds additional parameter to allow prefetch being used for the rel attribute. Also adds a syntax correction. * Update README.md with rel prop
1 parent 29d5918 commit 7f8a321

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ The most minimalist implementation requires two props: `id` from the YouTube you
257257
| playlist | boolean | Use `true` when your id be from a playlist |
258258
| playlistCoverId | string | The ids for playlists did not bring the cover in a pattern to render so you'll need pick up a video from the playlist (or in fact, whatever id) and use to render the cover. There's a programmatic way to get the cover from YouTube API v3 but the aim of this component is do not make any another call and reduce requests and bandwidth usage as much as possible |
259259
| poster | string. One of `default` `mqdefault` `hqdefault` `sddefault` `maxresdefault` | Defines the image size to call on first render as poster image. See: [https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api](https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api) |
260+
| rel | string | Default `preload`. allows for prefetch or preload of the link url |
260261
| webp | boolean | Default `false`. When set, uses the WebP format for poster images |
261262
| wrapperClass | string | Pass the string class that wraps the iFrame |
262263

β€Žsrc/lib/index.tsxβ€Ž

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface LiteYouTube {
2828
onIframeAdded?: () => void
2929
muted?: boolean,
3030
thumbnail?: string,
31+
rel?: string,
3132
}
3233

3334
export default function LiteYouTubeEmbed(props: LiteYouTube) {
@@ -41,7 +42,7 @@ export default function LiteYouTubeEmbed(props: LiteYouTube) {
4142
const mutedImp = props.muted ? "&mute=1" : "";
4243
const announceWatch = props.announce || "Watch";
4344
const format = props.webp ? 'webp' : 'jpg';
44-
const vi = props.webp ? 'vi_webp' : 'vi'
45+
const vi = props.webp ? 'vi_webp' : 'vi';
4546
const posterUrl = props.thumbnail || (!props.playlist
4647
? `https://i.ytimg.com/${vi}/${videoId}/${posterImp}.${format}`
4748
: `https://i.ytimg.com/${vi}/${videoPlaylisCovertId}/${posterImp}.${format}`);
@@ -65,6 +66,7 @@ export default function LiteYouTubeEmbed(props: LiteYouTube) {
6566
const playerClassImp = props.playerClass || "lty-playbtn";
6667
const wrapperClassImp = props.wrapperClass || "yt-lite";
6768
const onIframeAdded = props.onIframeAdded || function () { };
69+
const rel = props.rel ? 'prefetch' : 'preload';
6870

6971
const warmConnections = () => {
7072
if (preconnected) return;
@@ -85,7 +87,7 @@ export default function LiteYouTubeEmbed(props: LiteYouTube) {
8587
return (
8688
<>
8789
<link
88-
rel="preload"
90+
rel={rel}
8991
href={posterUrl}
9092
as="image"
9193
/>

0 commit comments

Comments
Β (0)