feat(gallery): preload images
release.yaml / publish (push) Successful in 3m4s

This commit is contained in:
schreifuchs committed 2026-09-10 14:02:05 +02:00
1 parent c678c7aa45
commit 72bc974aa6
3 files changed
+24 -1

No files matched your search

+14 -1
View File
@@ -1,12 +1,16 @@
package restgallery
import (
"fmt"
"log/slog"
"net/http"
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/templer"
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/pages"
)
const preloadCount = 6
func (h *Handler) gallery(w http.ResponseWriter, r *http.Request) {
imgs, err := h.srv.GetGallerySet(r.Context())
if err != nil {
@@ -14,5 +18,14 @@ func (h *Handler) gallery(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
return
}
h.r.Render(r.Context(), w, r, pages.GallerySet(imgs))
ctx := r.Context()
for i, image := range imgs.LG.Images {
if i > preloadCount {
break
}
slog.Info("preloading images", "img", image.UID)
ctx = templer.AppendHeader(ctx, fmt.Sprintf(`<link rel="preload" href="%s" as="image" />`, image.URL()))
}
h.r.Render(ctx, w, r, pages.GallerySet(imgs))
}