From ce6b5ebb39a967769ac1ba51a8e1b65ecaa9280e Mon Sep 17 00:00:00 2001 From: Florian Greistorfer Date: Fri, 6 Feb 2026 10:51:36 +0100 Subject: [PATCH] different prefetch --- files/global.css | 7 +++++++ templates/functionality.js | 27 +++++++++++++-------------- templates/index.html.j2 | 3 ++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/files/global.css b/files/global.css index 039d292..390319c 100644 --- a/files/global.css +++ b/files/global.css @@ -353,6 +353,13 @@ input { left: calc(50% + 1em - 1px); } +.imgprefetch { + position: absolute; + width: 0; + height: 0; + overflow: hidden; +} + @media screen and (max-width: 1000px) { .column { -ms-flex: 25%; diff --git a/templates/functionality.js b/templates/functionality.js index e8987de..0086590 100644 --- a/templates/functionality.js +++ b/templates/functionality.js @@ -47,22 +47,21 @@ class PhotoGallery { } prefetch(imgIndex) { - if (this.controllers[imgIndex]) { - this.cancel(imgIndex); - } - const controller = new AbortController(); - const signal = controller.signal; - this.controllers[imgIndex] = controller; - const urlToFetch = this.shown[imgIndex]?.src; - if (urlToFetch) { - fetch(urlToFetch, { method: "GET", signal }).catch(() => {}); - } + const prefetchDiv = document.getElementById("img-prefetch"); + if (!prefetchDiv) return; + + const img = document.createElement("img"); + img.src = this.shown[imgIndex]?.src || ""; + prefetchDiv.appendChild(img); } cancel(imgIndex) { - if (this.controllers[imgIndex]) { - this.controllers[imgIndex].abort(); - delete this.controllers[imgIndex]; + const prefetchDiv = document.getElementById("img-prefetch"); + if (!prefetchDiv) return; + + const img = prefetchDiv.querySelector(`img[src="${this.shown[imgIndex]?.src || ""}"]`); + if (img) { + prefetchDiv.removeChild(img); } } @@ -393,7 +392,7 @@ class PhotoGallery { if (!isNaN(index)) this.openSwipe(index); }); - imagelist.addEventListener("mouseover", (event) => { + imagelist.addEventListener("mouseenter", (event) => { const img = event.target.closest("img"); if (!img || !img.dataset.index) return; const index = parseInt(img.dataset.index); diff --git a/templates/index.html.j2 b/templates/index.html.j2 index 968461e..1c4977b 100644 --- a/templates/index.html.j2 +++ b/templates/index.html.j2 @@ -57,7 +57,7 @@ - +<>
+