首页 > 解决方案 > How do I avoid lazyloading placeholders (LQIP) from being cached in Google Images

问题描述

I would like to lazyload my images via medium-like Low Quality Image Placeholder (LQIP) technic as part of current lighthouse metrics optimisations (particularly FCP / LCP)

I plan to serve Server-Side-Rendered-HTML with small 10px-wide-images (LQIPs) and then on the client I will load original images via javascript (see snippet example).

This approach really helps to boost LCP / FCP, but my main concern here is Google's Images Search results - as my SSR HTML contains only small 10px images, and only Client-side JS will load fullsize 540px images.

What will google show on its images tab - will it cache my LQIPs? How do I avoid them from being cached?

function revealFullsize() {
  document.querySelector(".lqip").classList.add("hide");
  document.querySelector(".original").classList.remove("hide");
}

function loadFullsize(img) {
  document.querySelector(".original").src = "https://lqip.lqip.app/images/open.jpg?w=3000";
}
* {
  margin: 0;
  padding: 0;
}

.img-container {
  position: relative;
  width: 300px;
  height: 200px;
  overflow: hidden;
  border-radius: 5px;
  margin: 20px;
}

img {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

.lqip {
  filter: blur(10px);
  transform: scale(1.1);
  transition: opacity .7s;
}

.hide {
  opacity: 0;
}
<div class="img-container">
  <img class="original hide" onload="revealFullsize()" />
  <img src="https://lqip.lqip.app/images/open.jpg?w=20" class="lqip" onload="loadFullsize(this)" />
  <noscript>
    <img class="original" src="https://lqip.lqip.app/images/open.jpg?w=3000"/>
  </noscript>
</div>

标签: javascripthtmlcsslazy-loadinglighthouse

解决方案


推荐阅读