Fix #17: Bildoptimierung – WebP, Lazy Loading, Caching #22

Merged
greggy merged 5 commits from feature/issue-17-bildoptimierung-webp into main 2026-05-19 15:29:05 +02:00
Showing only changes of commit 73635a5f03 - Show all commits

View File

@@ -46,10 +46,11 @@ $(function () {
// Lightbox gallery grid items
$(document).on("click", ".grid-item", function () {
var src = $(this).data("img") || $(this).find("img").attr("src");
$("#lightboxImg").on("error", function () {
$("#lightboxImg").off("error").on("error", function () {
// WebP fallback: try original format
var fallback = src.replace(/\.webp$/, src.endsWith('.webp') ? '.png' : '.jpg');
if ($(this).attr('src') !== fallback) $(this).attr('src', fallback);
if ($(this).attr('src').endsWith('.webp')) {
$(this).attr('src', src.replace(/\.webp$/, '.png'));
}
});
$("#lightboxImg").attr("src", src);
$("#lightbox").addClass("open");
@@ -59,9 +60,10 @@ $(function () {
// Lightbox floor plan images in Raumaufteilung
$(document).on("click", ".floor-plan img[data-img]", function () {
var src = $(this).data("img");
$("#lightboxImg").on("error", function () {
var fallback = src.replace(/\.webp$/, '.png');
if ($(this).attr('src') !== fallback) $(this).attr('src', fallback);
$("#lightboxImg").off("error").on("error", function () {
if ($(this).attr('src').endsWith('.webp')) {
$(this).attr('src', src.replace(/\.webp$/, '.png'));
}
});
$("#lightboxImg").attr("src", src);
$("#lightbox").addClass("open");