Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lazyvids

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazyvids

A small utility to lazy-load autoplay HTML5 videos once they enter the viewport.

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
92
increased by17.95%
Maintainers
1
Weekly downloads
 
Created
Source

lazyvids.js

A small utility to lazy-load autoplay HTML5 videos once they enter the viewport.

Installation

Install using your favourite package manager.

$ yarn add lazyvids

Import into your project.

import 'lazyvids';

Usage

lazyvids.js works by setting attributes on HTML5 video elements, and playing the videos once they are scrolled into view.

  1. Add a [data-lazyvids] attribute to <video> elements that you want to lazy-play.

  2. Add preload="none" to the <video> to prevent the browser from downloading it when out of view. preload="metadata" is preferred, but does not work as it should in Safari (🙄).

  3. It's best practice to also include muted and playsinline attributes, but the library will add them by default.

  4. Provide the <video> with a poster image attribute. A poster image is required for the video to lazy-play by default, but this behaviour can be changed using the relevant lazyvidsConfig option.

<video
  data-lazyvids
  muted
  playsinline
  preload="none"
  poster="poster.jpg"
  src="example.mp4"
></video>

<video data-lazyvids muted playsinline preload="none" poster="poster.jpg">
  <source src="example.webm" type="video/webm" />
  <source src="example.mp4" type="video/mp4" />
</video>

Options

Configuration options are available using a lazyvidsConfig object on the global window object. This must be included in the HTML before the lazyvids script.

<script>
  window.lazyvidsConfig = lazyvidsConfig || {};
  lazyvidsConfig = {
    logLevel: 'silent',
    ignoreHidden: false,
    minBandwidth: 0,
    reduceData: false,
    requirePoster: true,
  };
</script>
OptionTypeDefault ValueDescription
logLevelstringsilentSet logging level: verbose, warn, silent.
ignoreHiddenbooleanfalseSet whether to skip <videos> with display: hidden.
minBandwidthnumber0If reducedData is true, set threshold above which videos will play.
reduceDatabooleanfalseIf true, will not play videos if data saver is enabled or bandwidth is below minBandwidth.
requirePosterbooleantrueWhen false, will lazy-play video even if poster image is missing.

FAQs

Package last updated on 18 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc