I don't think that webp-format pictures look different then jpg or png formats. However, they are significantly smaller in file size, which gives you a dramandious speed boost when loading your page.
Neverthelss, make sure you have a fallback jpg in place. Also lazy loading of higher resolution images is a nice way to increase your performance.
I am currently developing this page here: https://www.garden-shop.at/ . Take a look at how the large image in the background of the hero section is been loaded and smoothly exchanged only after its loading has been finished. Here is the function that I am using:
Code
document.addEventListener("DOMContentLoaded", function () {
const lazyloadElements = document.querySelectorAll(".lazyload");
lazyloadElements.forEach((el) => {
const highResImage = el.getAttribute("data-bg");
if (highResImage) {
// Preload the high-quality image
const img = new Image();
img.src = highResImage;
console.log("start preload: ", highResImage);
img.onload = function () {
console.log("finished preload: ", highResImage);
// Set the high-quality image to the ::before pseudo-element
el.style.setProperty("--bg-image-high-res", `url('${highResImage}')`);
// Add a class to trigger the fade-in effect
el.classList.add("loaded");
};
}
});
});
Alles anzeigen