如何在NUXT中正确地延迟负载图像?
是否可以同时将-SSR和Lazy -Loading用于客户端的图像。这是我的情况。我的标记与img [src]一起渲染,在我的chrome浏览器中,我按Ctrl+u,可以看到所有图像都具有SRC属性(SEO机器人会识别它们,我很高兴),但是在客户端,我需要拥有IMG [DATA-SRC]用于延迟加载。如果我在服务器端上有一个data-src属性,则SEO机器人找不到任何SRC(按Ctrl + U将证明这一点),但是所有图像都将带有懒惰加载...如果我过滤标记在接收客户端之前(实际上我确定如何在NUXT中实现它)。请提出任何解决问题的想法或指示?
Is it possible to use both - ssr and lazy-loading for images on the client side. Here is my situation. My markup is rendered with img[src], in my chrome browser I press ctrl+U and can see all images have an src attribute (seo robots will recognize them and I'm happy), but on the client side I need to have img[data-src] for lazy-loading. If I have a data-src attribute on the server-side, the seo robots won't find any src (pressing ctrl + U will prove it), but all images will be displayed with lazy loading... Should I filter the markup before receiving on the client side (actually I'm sure how to implement it in nuxt). Please suggest any ideas or directions to solve the issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是实现以下方法的方法:
6
的图像过滤,您会发现,如果增加视口&gt,您将获得一些网络请求。 1000px(滚动滚动时,懒惰加载)对此不满意吗?这是一个 InterSectionObserver 示例,示例更为复杂,但也更加灵活。
Here is how to achieve the following:
loading="lazy"
is doing the heavy lifting here, it's working fine on not-so old browsers6
, you will see that you'll get some network requests going out if increasing the viewport > 1000px (lazy-loaded when scrolling still)Not satisfied with this one? Here is an intersectionObserver example, a bit more complex but also more powerful/flexible.