diff --git a/public/s/js/globalchat.js b/public/s/js/globalchat.js
index 33862cf..fce4b31 100644
--- a/public/s/js/globalchat.js
+++ b/public/s/js/globalchat.js
@@ -23,6 +23,22 @@
let chatFocused = document.hasFocus();
const ytOembedCache = new Map(); // videoId → {title, author_name}
+ // Shared IntersectionObserver for lazy-loading embedded images.
+ // Images are rendered with data-lazy-src; this observer sets the real src
+ // when the image is within 200px of the visible scroll area.
+ const lazyImgObserver = new IntersectionObserver((entries) => {
+ for (const entry of entries) {
+ if (!entry.isIntersecting) continue;
+ const img = entry.target;
+ const src = img.dataset.lazySrc;
+ if (src) { img.src = src; delete img.dataset.lazySrc; }
+ lazyImgObserver.unobserve(img);
+ }
+ }, {
+ rootMargin: '200px', // start loading 200px before entering viewport
+ threshold: 0
+ });
+
function updateBadge() {
const badge = document.getElementById('gchat-badge');
const bubble = document.getElementById('gchat-reopen-bubble');
@@ -187,7 +203,7 @@
'gi'
);
html = html.replace(imageRegex, url =>
- `
`
+ `
`
);
// 6b. Raw video URLs from allowed hosts →