javascript - 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>
解决方案
推荐阅读
- networking - 是否可以将 Openvswitch 网桥与两个不同的接口绑定?
- node.js - heroku 的 typescript 部署失败
- html - Angular - 从焦点中排除 div
- sql-server - 排除意义相同但值不同的行
- python - loc[ ] 是 Pandas 中的一个函数吗
- django - Django Microsoft AD 身份验证
- node.js - Node.js 多个请求同时返回一个结果
- git - 切换到管道内的另一个分支?
- java - 哪些 ClientConfiguration 设置最适合建立 Elasticsearch 连接
- google-apps-script - Google Apps 脚本 - Gmail - 是否可以将邮件作为附件转发?