From a9b3b28d001941921aa70d37fdc87c758a163a44 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 05 Jun 2026 16:47:03 +0000
Subject: [PATCH] =Some hefty changes to FeedBlock. Transitioning to loading first page in php to save on extra requests. Got a bit to do yet, but I have to work on Northeh for a bit here.
---
src/video/view.js | 55 +++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 45 insertions(+), 10 deletions(-)
diff --git a/src/video/view.js b/src/video/view.js
index 8974786..76bcd1a 100644
--- a/src/video/view.js
+++ b/src/video/view.js
@@ -1,12 +1,47 @@
-const observer = new IntersectionObserver((entries) => {
- entries.forEach(entry => {
- if (entry.isIntersecting) {
- loadVideo(entry.target);
- observer.unobserve(entry.target);
- }
- });
-});
+/** view.js **/
+document.addEventListener("DOMContentLoaded", function () {
+ const lazyVideos = [].slice.call(
+ document.querySelectorAll(".video-container video")
+ );
-document.querySelectorAll('.video-container .placeholder').forEach(el => {
- observer.observe(el);
+ // Build a helper to actually set sources + load
+ function loadVideo(video) {
+ const sources = video.querySelectorAll("source[data-src]");
+ sources.forEach(source => {
+ source.src = source.dataset.src;
+ });
+ video.load();
+ }
+
+ // --- 1. IntersectionObserver (best case) ---
+ if ("IntersectionObserver" in window) {
+ const lazyVideoObserver = new IntersectionObserver(
+ function (entries, observer) {
+ entries.forEach(entry => {
+ if (entry.isIntersecting) {
+ loadVideo(entry.target);
+ observer.unobserve(entry.target);
+ }
+ });
+ },
+ {
+ rootMargin: "200px 0px",
+ threshold: 0.1,
+ }
+ );
+
+ lazyVideos.forEach(video => lazyVideoObserver.observe(video));
+ return;
+ }
+
+ // --- 2. Fallback: requestIdleCallback ---
+ if ("requestIdleCallback" in window) {
+ requestIdleCallback(() => {
+ lazyVideos.forEach(video => loadVideo(video));
+ });
+ return;
+ }
+
+ // --- 3. Final fallback: load immediately ---
+ lazyVideos.forEach(video => loadVideo(video));
});
--
Gitblit v1.10.0