Skip to content

Initially render with a low quality thumbnail for loading speeds, then load a higher res thumbnail when idle #62

@FunctionDJ

Description

@FunctionDJ

Title pretty much says it all.
I was curious so i wrote this custom hook who's return value i pass to the poster prop:

const useKindaLazyYouTubeThumbnail = () => {
  const [imgRes, setImgRes] = useState<"mqdefault" | "maxresdefault">("mqdefault");

  useEffect(() => {
    setTimeout(() => {
      setImgRes("maxresdefault");
    }, 5000);
  }, []);

  return imgRes;
};

What do you guys think? I noticed that changing the poster will show a blank thumbnail for a brief moment because the new thumbnail needs to get downloaded. I've already tried putting a prefetch element into the , but couldn't get it to work yet (it doesn't create a request):

<link rel="prefetch" href={`https://i.ytimg.com/vi_webp/${id}/maxresdefault.webp`}/>

By the way i think it would be cool if the type for the poster prop was importable. You can technically get to it through Parameters<typeof LiteYouTubeEmbed>["0"]["poster"] but yeah i'll let it speak for itself lmao

I'll make a PR for that little export.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions