Lazy YouTube Player
Embed YouTube videos with lazy loading for faster page loads and improved performance.
Published on: 16/11/2024π Project Overview
Lazy YouTube Player is a lightweight, customizable YouTube player. It provides a simple way to embed YouTube videos with lazy loading capabilities, improving your websiteβs performance.
β¨ Features
- Lazy loading of YouTube videos using Intersection Observer API
- TypeScript support for improved developer experience
- Customizable player options (thumbnail, play button, etc.)
- Accessibility improvements with ARIA attributes
- Responsive design
- Error handling for invalid video IDs or API failures
π₯ Installation
Follow these steps to set up Lazy YouTube Player on your machine.
- Add the script to your HTML file:
<script type='module'
src="https://cdn.jsdelivr.net/npm/lazy-youtube-player@v0.3.0/yt-player.min.js"
defer
></script>- Add the stylesheet to your HTML file:
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/lazy-youtube-player@v0.3.0/yt-player.min.css"
/>π― Usage
Hereβs a basic example of how to use the Lazy YouTube Player in a website:
<div
class="NexosYt"
data-embed="YT_VIDEO_ID"
></div>π‘ You can also customize thumbnail data-thumbnail="CUSTOM_THUMBNAIL_URL", its optional.
π§ API
The LazyYouTubePlayer component accepts the following props:
NexosYT(string, required): The YouTube Player Class.videoId(string, required): The YouTube video ID.thumbnailUrl(string, optional): Custom thumbnail URL. If not provided, the default YouTube thumbnail will be used.width(number, optional): The width of the player. Default: 640.height(number, optional): The height of the player. Default: 360.
π€ Contributing
We β€οΈ contributions! Follow these steps to contribute:
- π΄ Fork the repository
- πΏ Create a new branch (
git checkout -b feature/AmazingFeature) - πΎ Commit your changes (
git commit -m 'Add some AmazingFeature') - π Push to the branch (
git push origin feature/AmazingFeature) - π Open a Pull Request
π See our Contribution Guidelines for more details.
π License
This project is licensed under the MIT License. See the LICENSE file for details.
π¬ Contact & Community
π¬ Join us on Discord: Click Here
π¦ Follow on Twitter: @nexoscreator
π§ Email: contact@nexoscreator.tech
If you find this project helpful, please consider starring β the repository or sponsoring π on GitHub!
Created with β€οΈ by @nexoscreator