Lightbox: load only the current video, so neighbouring slides don't compete for bandwidth

This commit is contained in:
zyphlar
2026-11-07 18:05:12 -08:00
parent a949d64790
commit d4ce4444b8
+13 -2
View File
@@ -67,7 +67,11 @@ function buildDataSource () {
return { return {
html: html:
'<div class="pswp__video-wrap">' + '<div class="pswp__video-wrap">' +
'<video controls playsinline poster="' + escapeAttr(item.thumbnailUrl) + '">' + // preload="none": PhotoSwipe mounts the neighbouring slides too, and
// their default metadata fetch (often two chunks each, when the MP4
// index sits at the end of the file) competes for the uplink with
// the video being opened. contentActivate upgrades the current one.
'<video controls playsinline preload="none" poster="' + escapeAttr(item.thumbnailUrl) + '">' +
'<source src="' + escapeAttr(v.src) + '"' + typeAttr + '>' + '<source src="' + escapeAttr(v.src) + '"' + typeAttr + '>' +
'</video>' + '</video>' +
'</div>' '</div>'
@@ -304,6 +308,12 @@ export function initLightbox () {
} }
}) })
// Start buffering only the video on screen, as soon as its slide is current
state.lightbox.on('contentActivate', ({ content }: { content: { element?: HTMLElement } }) => {
const video = content.element?.querySelector('video')
if (video && video.preload !== 'auto') video.preload = 'auto'
})
// Video autoplay (off by default, ipp.lightbox.autoPlayVideos). PhotoSwipe // Video autoplay (off by default, ipp.lightbox.autoPlayVideos). PhotoSwipe
// fires contentActivate/contentDeactivate as slides become / stop being the // fires contentActivate/contentDeactivate as slides become / stop being the
// current slide, including the initial slide on open. // current slide, including the initial slide on open.
@@ -342,7 +352,8 @@ export function initLightbox () {
const video = content.element?.querySelector('video') const video = content.element?.querySelector('video')
if (video) { if (video) {
video.pause() video.pause()
video.currentTime = 0 // Seeking (even to 0) fetches again; skip it for a video never played
if (video.currentTime > 0) video.currentTime = 0
} }
}) })