Skip to content

Lazy Load Iframes video show image#1000

Draft
timotei-litespeed wants to merge 1 commit into
litespeedtech:devfrom
timotei-litespeed:Videos-Lazyload
Draft

Lazy Load Iframes video show image#1000
timotei-litespeed wants to merge 1 commit into
litespeedtech:devfrom
timotei-litespeed:Videos-Lazyload

Conversation

@timotei-litespeed

Copy link
Copy Markdown
Contributor

Load Video Image

Adds a new Load Video Image option (Page Optimization → Media Settings) that replaces YouTube / Vimeo / Wistia / Dailymotion <iframe>s with a thumbnail + play-button facade. Click on image reconstructs a fresh iframe with autoplay.

Behavior

  • New option O_MEDIA_IFRAME_LAZY_VIDEO_IMG (default off), gated on Lazy Load Iframes.
  • Media::_finalize() runs the facade pass before the existing iframe-lazy pass — video iframes become <div>s, non-video iframes still get data-src treatment.
  • Thumbnails: YouTube/Dailymotion via direct URL, Vimeo/Wistia via oEmbed (3 s timeout). Cached as transients (30 d hit, 10 min miss).
  • Skips: missing src; lazy data-attrs, excluded class; autoplay=1\|true in query, URL filter, unknown provider, dup markup.

Facade markup

<div class="litespeed-video-facade"
     data-lsvf-src="..."
     data-lsvf-attrs="<base64 JSON of attrs minus src>"
     style="max-width:Wpx;aspect-ratio:W/H;background-image:url(thumb);">
  <button type="button" aria-label="Play video" class="litespeed-video-play"></button>
</div>

No <iframe> in server HTML. Facade script carries data-no-optimize="1" so JS Delay won't defer it.

Filters

litespeed_video_lazy_providers, litespeed_video_lazy_skip_urls, litespeed_video_lazy_skip, litespeed_video_lazy_thumbnail, litespeed_video_lazy_facade_html. Reuses existing class-exclude filters.

Limitations

  • No <noscript> fallback — JS off = no playback.
  • First render of a new Vimeo/Wistia URL pays one oEmbed call.
  • Self-closing <iframe /> and JS-driven autoplay aren't detected.
  • CSS-only sizing falls back to 16/9.

Testing

Enable both toggles, drop YouTube / YouTube-autoplay / Vimeo / Wistia / Dailymotion / class-excluded iframes into a page. Verify facades render, autoplay iframes pass through, click swaps in a working iframe.

@timotei-litespeed timotei-litespeed marked this pull request as draft June 9, 2026 13:45
Add functionality - Video Lazyload
Add filter for play button
@Tymotey Tymotey force-pushed the Videos-Lazyload branch from bb44cba to 8faa75a Compare June 9, 2026 13:50
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.

1 participant