minimalist-video-player

A highly efficient video player web component designed for minimal CPU usage and optimized bandwidth. Supports Vimeo and YouTube, loading content on-click for faster initial page speeds.

Active Pure Nim score 65/100 · last commit 2026-11-06 · 1 stars · tests present · no docs generated

Summary

Latest Version Unknown
License Unknown
CI Status Failing
Stars 1
Forks 0
Open Issues 0
Last Commit 2026-11-06
Downloads 0
Last Indexed 2026-12-04 15:11

Installation

nimble install minimalist-video-player
choosenim install minimalist-video-player
git clone https://gitlab.com/gitmatlab/minimalist-video-player

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
minimalist-video-player ✓ ✓ ✓ - - - - - - -

README

minimalist-video-player

pipeline status

A lightweight web component that embeds YouTube and Vimeo videos without loading anything from the provider until the visitor clicks play. Until then it shows a splash image provided by your page, and it can ask for cookie consent first.

Live demo: https://gitmatlab.gitlab.io/minimalist-video-player/

The problem

A YouTube or Vimeo embed, done the standard way, loads the provider's complete player when the page loads: scripts, styles, fonts and tracking, whether anybody watches the video or not. That costs bandwidth, slows down the page (Core Web Vitals), and contacts Google or Vimeo before the visitor has agreed to anything.

How it works

  • The page shows its own splash image, any <img> inside the element. Nothing is requested from the provider.
  • On click, the player checks consent, then inserts the provider's iframe with autoplay: youtube-nocookie.com for YouTube, dnt=true for Vimeo.
flowchart TD
    A[Visitor clicks play] --> B{cookie-banner set?}
    B -- no --> P[Insert video iframe]
    B -- yes --> C{Consent manager usable?}
    C -- no --> M[Error dialog with link to the provider's page]
    C -- yes --> D{Consent given?}
    D -- yes --> P
    D -- no --> E[Consent dialog]
    E -- accept --> P
    E -- cancel --> X[Nothing is loaded]

Usage

Build the bundle (npm ci && npm run build) and include build/minimalist-video-player.min.js:

<script src="minimalist-video-player.min.js" defer></script>

<minimalist-video-player platform="youtube" video-id="XPDcLCZIOeM">
  <img src="splash.jpg" alt="Our product in 60 seconds">
</minimalist-video-player>
Attribute Required Description
video-id yes The video's id on YouTube or Vimeo.
platform no youtube (default) or vimeo.
cookie-banner no Name of the consent manager to ask. Currently supported: CookieScript.
cookie-banner-text no JSON object that replaces the default dialog texts, e.g. for translations. Keys: consentTitle, consentClose, consentText01, consentSettings, consentText02, consentAllow, consentCancel, missingTitle, missingText, missingOpen, missingClose.

platform and video-id are read once, when the element is added to the page. To switch the video, replace the element (see the demo page).

Consent handling

Situation What the player does
No cookie-banner attribute Plays directly. The site owner decided not to ask.
Consent manager reports consent Plays directly.
Consent manager reports no consent Shows a consent dialog. Accept stores the consent in the consent manager and plays the video.
Consent manager is configured but missing, unknown or failing Shows an error dialog and logs a warning. The visitor can open the video on the provider's site. Nothing is loaded on this page.

Without cookie-banner, the player does not ask for consent. Whether that is legally sufficient is the site owner's responsibility.

Performance

The same YouTube video on 2 pages: 1. Standard YouTube embed 2. minimalist-video player - Spash image 1440 px WebP (79 kB) - Measured in November 2026 with Chrome in an incognito window, Lighthouse in mobile mode, and the DevTools network panel with the cache disabled.

Standard YouTube embed minimalist-video-player
Requests 19–20 3
Requests to third parties 18–19 0
Transferred 1,158 kB 96.5 kB
Transferred from third parties 1,157 kB 0 kB
Lighthouse performance score 98 100
Largest Contentful Paint 1.8 s 1.4 s
Total Blocking Time 0 ms 0 ms

The difference is in what goes over the network and to whom: about 12 times less data, and no request to Google or YouTube before the click. Of the 96.5 kB, 79 kB are the splash image; the component itself is 3 kB gzipped.

Reproduce the measurement

The two pages are in bench/. Build the component and serve the repository folder:

npm run build
npx http-server-spa . build/index.html 8080

Then, for each of the two pages:

  1. Open a Chrome window in incognito mode (Cmd+Shift+N on macOS, Ctrl+Shift+N on Windows and Linux), so browser extensions don't affect the result.
  2. Open the page:
  3. standard embed: http://localhost:8080/bench/iframe.html
  4. component: http://localhost:8080/bench/player.html
  5. Open DevTools (Cmd+Option+I / Ctrl+Shift+I), go to the Lighthouse tab, choose mode Navigation, device Mobile, category Performance, and click Analyze page load. Run it three times and take the middle value.
  6. For requests and transferred data, go to the Network tab, tick Disable cache

Decisions and trade-offs

  • A web component without a framework. It works in any page, CMS or framework, has no runtime dependencies, and the bundle is 8.5 kB minified, 3.0 kB gzipped.
  • Fail closed. If a consent manager is configured but cannot be used (not loaded, blocked by a browser extension, misspelled), the video is not loaded. The developer gets a console warning; the visitor gets an explanation instead of a silent failure.
  • Dialogs are built with createElement, not innerHTML. Texts from cookie-banner-text become text nodes, so they cannot inject markup or event handlers. The price: texts cannot contain HTML (e.g. <b>), and the code is less compact than an HTML template.
  • No DOMPurify. I evaluated it to keep HTML in the dialog texts. It would have grown the bundle from 3.2 kB to 14.4 kB gzipped (4.5×), for a component whose purpose is saving bandwidth.
  • The video id is URL-encoded, so unexpected characters cannot change the structure of the iframe URL.
  • No preconnect on hover. Warming up the connection on hover would save a few hundred milliseconds on desktop and almost nothing on touch devices, where the event fires at the tap itself. In exchange it would contact the provider before the click and before consent. Nothing is requested from the provider until the visitor clicks play.
  • Consent states are explicit values (not-required, granted, denied, unavailable) instead of a boolean plus exceptions. A missing consent manager is an expected situation, not an error.

Known limitations

  • Video ids are not validated, only URL-encoded. YouTube ids match /^[A-Za-z0-9_-]{11}$/, Vimeo ids /^\d+$/.
  • Only CookieScript is supported. Other consent managers need an adapter of their own.
  • No consent storage without a consent manager. In the error case, open on the provider's site is the only option.
  • Focus is not moved into the dialogs. They close with Escape, but keyboard users have to tab to them.
  • Styles are global. The CSS is added to the page's <head> and uses plain class names (consent-*, playbutton), which could collide with the site's own styles.

Development

Requires Node.js 24 (see .nvmrc).

npm ci            # install exactly the locked versions
npm start         # build in watch mode and serve the demo on http://localhost:1338
npm test          # run the tests (Vitest + happy-dom)
npm run build     # bundle to build/

GitLab CI runs the tests and the build on every push. Pushes to main publish the demo page on GitLab Pages.

How I used AI

The player is older than my use of AI on it. I built the first version, for Vimeo only, in December 2021, added YouTube support in April 2024, and the consent dialog and translations in February 2026. It worked before this revision.

In November 2026 I revised it with Claude (Anthropic) as a pair programmer: tests, CI, security and accessibility fixes, and this documentation. I reviewed every change before committing it.

Generated by AI, reviewed by me: the review that found the original bugs, the test suite (written as failing tests first, then made green), the error dialog for a missing consent manager, the rewrite of the dialogs from innerHTML to createElement, the GitLab CI configuration and the demo page.

Written by me: the fixes for URL encoding, the consent states, invalid JSON, the play button as a real <button> and closing dialogs with Escape.

Where I decided differently than suggested:

  • On the demo page I replaced a generic event-handler helper with explicit handlers. The helper saved a few lines, but was harder to read, and the page's purpose is documentation.
  • I dropped DOMPurify after measuring its size.
  • I dropped a test that checked the dialog text for words like "YouTube". I made the texts platform-neutral instead of maintaining a word blacklist.
  • I postponed id validation to keep the focus on the consent handling.

What review caught that tests didn't: removeEventListener('onKeyDown', …) instead of 'keydown'. All tests were green, but the Escape listener was never removed. Green tests only prove what they test.

Credits

The idea of rendering a lightweight play button and inserting the provider iframe only on click comes from lite-vimeo-embed by Wesley Luyten, itself a port of Paul Irish's lite-youtube-embed.

My own work: one web component for both YouTube and Vimeo, a splash image provided by the page (no request to the provider before the click), consent handling with CookieScript, and internationalised dialog texts.

I deliberately left out their preconnect on hover: it opens a connection to the provider before the visitor has clicked or consented, and the time it saves is small compared with loading the provider's player.

License

MIT, see LICENSE.