喜大普奔!Chrome 75 将原生支持图片懒加载

(给前端大全加星标,提升前端技能


原创整理:前端大全(ID:FrontDev)


4 月 6 日,Google 的 Chrome & Web 平台工程经理 Addy Osmani 在个人博客发文,介绍到 <img> 和 <iframe> 的 loading 将新增一个属性:lazy


使用方法如下:

<img src="celebration.jpg" loading="lazy" alt="..." /><iframe src="video-player.html" loading="lazy"></iframe>

(代码块可左右滑动)

范例如下:

<!-- Lazy-load an offscreen image when the user scrolls near it --><img src="unicorn.jpg" loading="lazy" alt=".."/>
<!-- Load an image right away instead of lazy-loading --><img src="unicorn.jpg" loading="eager" alt=".."/>
<!-- Browser decides whether or not to lazy-load the image --><img src="unicorn.jpg" loading="auto" alt=".."/>
<!-- Lazy-load images in <picture>. <img> is the one driving image loading so <picture> and srcset fall off of that --><picture> <source media="(min-width: 40em)" srcset="big.jpg 1x, big-hd.jpg 2x"> <source srcset="small.jpg 1x, small-hd.jpg 2x"> <img src="fallback.jpg" loading="lazy"></picture>
<!-- Lazy-load an image that has srcset specified --><img src="small.jpg" srcset="large.jpg 1024w, medium.jpg 640w, small.jpg 320w" sizes="(min-width: 36em) 33.3vw, 100vw" alt="A rad wolf" loading="lazy">
<!-- Lazy-load an offscreen iframe when the user scrolls near it --><iframe src="video-player.html" loading="lazy"></iframe>


如果不出意外,Chrome 75 将正式默认支持图片懒加载。


目前 Chrome 版本是 73,默认不支持懒加载。如果你等不急,可以直接强制开启 Chrome 的懒加载特性。


  • 在 Chrome 地址栏中输入:chrome://flags/

  • 查找 Enable lazy image loading,把下图中两项设置成「Enable」

640?wx_fmt=png


推荐阅读

(点击标题可跳转阅读)

Chrome 的哪些功能改变了我们浏览网页的方式?

Chrome 调试技巧


觉得本文对你有帮助?请分享给更多人

关注「前端大全」加星标,提升前端技能

640?wx_fmt=png

喜欢就点一下「在看」呗~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值