Giter VIP home page Giter VIP logo

lazy-youtube-embed's Introduction

lazy-youtube-embed

GitHub GitHub package.json version

A fast, lightweight, lazy load, progressive enhancement YouTube embed. 🤯

  • NO DEPENDENCIES.
  • Progressive enhancement: Uses the a tag instead div or custom element. Older or javascript disabled browsers can go to YouTube anyway.
  • Lazy load: Load the video thumbnail using IntersectionObserver API.
  • The quality of the thumbnail is decided using Network Information API.

Install

$ npm install --save lazy-youtube-embed

Then with a module bundler like rollup or webpack, use as you would anything else:

// Using ES6 module
import lazyYoutubeEmbed from 'lazy-youtube-embed'

Or via CDN with script tag

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/logico/lazy-youtube-embed/dist/lazy-youtube-embed.css" />

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/lazy-youtube-embed.js" defer></script>

Usage

In HTML add an a tag with the source to the YouTube video and lazy-youtube-embed class:

<a href="https://youtu.be/3vBwRfQbXkg" class="lazy-youtube-embed">HOW TO FUNK IN TWO MINUTES</a>

lazy-youtube-embed must run after the DOM is loaded.

Comparison

These are test pages and results of performance. Faster to slower

1.- Lazy YouTube Embed.

LAZY-YOUTUBE-EMBED TEST PAGE

lite-youtube-embed

2.- Lite YouTube Embed repo.

LITE-YOUTUBE-EMBED TEST PAGE

lite-youtube-embed

3.- srcdoc technique css-tricks.

SRCDOC TEST PAGE

iframe

4.- AMP <amp-youtube> component amp-youtube.

AMP TEST PAGE

iframe

5.- <iframe> YouTube embed.

IFRAME TEST PAGE

iframe

lazy-youtube-embed's People

Contributors

janoamaral avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lazy-youtube-embed's Issues

Lighthouse issue with unnamed thumbnails

Hello! I have been using this plug-in for a while and I have tested my website with lighthouse and I have found this issue:

image

it says that the thumbnails does not have alt attributes. How can I fix it? Maybe the plug-in could take the video title as alt description.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.