Skip to content

feat: lazy-loading player#1017

Merged
tsi merged 13 commits intomasterfrom
VIDEO-18457-lazy-player
Apr 7, 2026
Merged

feat: lazy-loading player#1017
tsi merged 13 commits intomasterfrom
VIDEO-18457-lazy-player

Conversation

@tsi
Copy link
Copy Markdown
Collaborator

@tsi tsi commented Mar 31, 2026

Summary

Add a lazy option that defers Video.js initialization until the user clicks the player or scrolls it into view. The video element displays a native <video poster> with a styled big-play-button overlay, keeping the page lightweight until activation.

Changes

  • New lazy-player.js utility consolidating element resolution, placeholder preparation, overlay bootstrap, and deferred player loading into a single module.
  • New bootstrap-poster-url.js utility to resolve the poster URL from player options or cloudName/publicId.
  • player-api.js gains player() and players() async entry points that handle lazy bootstrap when lazy is set, falling back to normal videoPlayer() otherwise.
  • configSchema.json extended with a lazy option (true or { loadOnScroll: true }).
  • schedule.js refactored to reuse lazy-player.js utilities instead of duplicating element/poster logic.
  • SCSS additions for the .cld-lazy-preactivate-overlay wrapper (sizing overrides to coexist with Video.js defaults).
  • TypeScript declarations updated with player/players signatures.
  • New unit tests for placeholder, bootstrap, and poster URL utilities; old schedule-bootstrap tests replaced.
  • New docs/lazy-player.html (UMD) and docs/es-modules/lazy-player.html (ESM) example pages demonstrating click-to-load and scroll-to-load.

How to Test

  1. npm run test:unit - all 103 tests pass.
  2. Open docs/lazy-player.html - verify the player shows a poster with a play button; clicking initializes the full player with controls and autoplay.
  3. Click "Load Player" button - same behavior via loadPlayer() API.
  4. Scroll down to the second player - it auto-initializes when it enters the viewport.
  5. Open docs/es-modules/lazy-player.html for the ESM equivalent.

* Load player on-click
* Load player on-scroll
@tsi tsi requested a review from a team as a code owner March 31, 2026 09:06
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 31, 2026

Deploy Preview for cld-video-player ready!

Name Link
🔨 Latest commit 455f4de
🔍 Latest deploy log https://app.netlify.com/projects/cld-video-player/deploys/69d3b27d69ddc300089dc0bc
😎 Deploy Preview https://deploy-preview-1017--cld-video-player.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 31, 2026

Deploy Preview for cld-vp-esm-pages ready!

Name Link
🔨 Latest commit 455f4de
🔍 Latest deploy log https://app.netlify.com/projects/cld-vp-esm-pages/deploys/69d3b27d20eea500083cb2ba
😎 Deploy Preview https://deploy-preview-1017--cld-vp-esm-pages.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@tsi tsi self-assigned this Mar 31, 2026
Comment on lines +18 to +26
if (opts?.schedule?.weekly) {
const { shouldUseScheduleBootstrap, scheduleBootstrap } = await import('./schedule');
if (shouldUseScheduleBootstrap(opts)) {
return scheduleBootstrap(id, opts, ready);
}
}

if (shouldUseLazyBootstrap(opts)) {
return lazyBootstrap(id, opts, ready);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so i cant combine "schedule" with "lazy"?

Copy link
Copy Markdown
Collaborator Author

@tsi tsi Apr 6, 2026

Choose a reason for hiding this comment

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

That's a great question, I double-checked and yes, you can!
First of all, a scheduled player should always start with the lazy-bundle, otherwise you're loading the full-player just to display an image.
But even a player with schedule, when inside a video-schedule slot - it can still be "lazy" and load the full player only when clicked or scrolled-to 💪

Here's a quick example: https://codepen.io/tsi/pen/OPRwgVe

@tsi tsi merged commit 17246c5 into master Apr 7, 2026
10 checks passed
@tsi tsi deleted the VIDEO-18457-lazy-player branch April 7, 2026 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants