npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@robcruiz/lazy-embed

v1.0.3

Published

Lazy Embed Component

Readme

Lazy Embed: A Web Component for Lazy-Loaded Video Embeds

Built With Stencil

Lazy Embed is a lightweight, customizable web component that improves website performance by lazy-loading video embeds from YouTube, Vimeo, and other sources. Videos load only when needed, saving bandwidth and improving page load speed.

Live Demo

Features

  • 🚀 Performance: Only loads videos when they're needed
  • 🔍 SEO-friendly: Preview images load immediately while heavy video embeds are deferred
  • 🎮 Multiple trigger options: Load videos on click, visibility, or other custom events
  • 📱 Responsive: Automatically adapts to different screen sizes
  • 🌐 Framework-agnostic: Works in any web project - no framework required
  • Simple API: Easy to implement with just a few attributes

Installation

Option 1: Direct Script Import (CDN)

Add this to your HTML page:

<script type="module" src="https://unpkg.com/@robcruiz/lazy-embed"></script>

Option 2: NPM Installation

npm install @robcruiz/lazy-embed

Then import it in your JavaScript:

// ESM import
import '@robcruiz/lazy-embed';

// Or CommonJS
require('@robcruiz/lazy-embed');

Basic Usage

<lazy-embed 
  src="https://www.youtube.com/watch?v=dQw4w9WgXcQ" 
  preview-image="https://img.youtube.com/vi/dQw4w9WgXcQ/maxresdefault.jpg"
  alt="YouTube video"
  video-title="Example video">
</lazy-embed>

Available Properties

| Property | Description | Type | Default | |----------|-------------|------|---------| | src | URL of the video to embed (YouTube, Vimeo, etc.) | string | required | | preview-image | URL of the preview image to display | string | required | | alt | Alternative text for the preview image | string | 'Video preview' | | width | Width of the embed (px or %) | string | '100%' | | height | Height of the embed (px or %) | string | 'auto' | | video-title | Title of the video (for accessibility) | string | '' | | load-on-visible | Load video when it becomes visible in viewport | boolean | false | | load-on-parent-open | CSS selector for parent element that triggers loading when opened | string | '' | | load-on-click-selector | CSS selector for elements that trigger loading when clicked | string | '' |

Advanced Usage Examples

Load When Visible in Viewport

<lazy-embed 
  src="https://www.youtube.com/watch?v=dQw4w9WgXcQ" 
  preview-image="https://img.youtube.com/vi/dQw4w9WgXcQ/maxresdefault.jpg"
  load-on-visible="true">
</lazy-embed>

Load When Parent Element Opens

<div id="accordion-item">
  <button>Open Section</button>
  <div class="content">
    <lazy-embed 
      src="https://www.youtube.com/watch?v=dQw4w9WgXcQ" 
      preview-image="https://img.youtube.com/vi/dQw4w9WgXcQ/maxresdefault.jpg"
      load-on-parent-open="#accordion-item.active">
    </lazy-embed>
  </div>
</div>

Load When External Element is Clicked

<button id="load-video-btn">Load Video</button>

<lazy-embed 
  src="https://www.youtube.com/watch?v=dQw4w9WgXcQ" 
  preview-image="https://img.youtube.com/vi/dQw4w9WgXcQ/maxresdefault.jpg"
  load-on-click-selector="#load-video-btn">
</lazy-embed>

Browser Support

This component works in all modern browsers that support:

  • Web Components (Custom Elements v1)
  • IntersectionObserver API
  • MutationObserver API

Development

This component was built with Stencil.js, a toolchain for building reusable, scalable web components.

If you want to customize or contribute to this component:

# Clone the repository
git clone https://github.com/robruiz/lazy-embed.git
cd lazy-embed

# Install dependencies
npm install

# Start the development server
npm start

# Build for production
npm run build

# Run tests
npm test

Learn more about building with Stencil at their official documentation.

License

MIT