Skip to content

Conversation

crisbeto
Copy link
Member

Currently the youtube-player component loads the YouTube API and sets up the video on initialization. This can slow the page down a lot, because it loads and executes ~150kb of JavaScript, even though the video isn't playing.

These changes rework the youtube-player component to show the thumbnail of the video and a fake button instead. When the button is clicked, the API will be loaded and the video will be autoplayed, thus moving the YouTube API out of the critical path.

There are a few cases where the placeholder won't be shown:

  • A video that plays automatically.
  • When the youtube-player is showing a playlist, rather than a single video.

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: minor This PR is targeted for the next minor release dev-app preview When applied, previews of the dev-app are deployed to Firebase labels Nov 30, 2023
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Nov 30, 2023
Copy link

github-actions bot commented Nov 30, 2023

Deployed dev-app for 27c9ff5 to: https://ng-dev-previews-comp--pr-angular-components-28207-dev-wmb3qpc4.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

By default the `<youtube-player/>` will show a placeholder element instead of loading the API
up-front until the user interacts with it. This speeds up the initial render of the page by not
loading unnecessary JavaScript for a video that might not be played. Once the user clicks on the
video, the API will be loaded and the placeholder will be swapped out with the actual video.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth mentioning that the placeholder:

  • has a lower quality of the thumbnail (as I can see in the visual diff?)
  • does not show the title of the video? (or should we show that as part of the placeholder)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point, I'll call them out in the doc. I think that generally users won't notice the difference since they won't get to see the YouTube placeholder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it seems like we can use the maxresdefault.jpg placeholder instead. When I was testing earlier the highest-quality webp videos didn't have placeholders, but the jpg ones do. I'll switch it to the high quality one and we can revisit it later if it's problematic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I ended up over-engineering it a bit 😅. Now users can choose between 3 different options since some super-old videos only have really low-quality thumbnails.

…older image

Currently the `youtube-player` component loads the YouTube API and sets up the video on initialization. This can slow the page down a lot, because it loads and executes ~150kb of JavaScript, even though the video isn't playing.

These changes rework the `youtube-player` component to show the thumbnail of the video and a fake button instead. When the button is clicked, the API will be loaded and the video will be autoplayed, thus moving the YouTube API out of the critical path.

There are a few cases where the placeholder won't be shown:
* A video that plays automatically.
* When the `youtube-player` is showing a playlist, rather than a single video.
Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice work!

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Nov 30, 2023
@crisbeto crisbeto merged commit b7c47c3 into angular:main Nov 30, 2023
essjay05 pushed a commit to essjay05/angular-components that referenced this pull request Dec 6, 2023
…older image (angular#28207)

Currently the `youtube-player` component loads the YouTube API and sets up the video on initialization. This can slow the page down a lot, because it loads and executes ~150kb of JavaScript, even though the video isn't playing.

These changes rework the `youtube-player` component to show the thumbnail of the video and a fake button instead. When the button is clicked, the API will be loaded and the video will be autoplayed, thus moving the YouTube API out of the critical path.

There are a few cases where the placeholder won't be shown:
* A video that plays automatically.
* When the `youtube-player` is showing a playlist, rather than a single video.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker detected: feature PR contains a feature commit dev-app preview When applied, previews of the dev-app are deployed to Firebase P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants