图片加载优化

132 阅读1分钟

优化前:

image.png

优化后:

image.png

代码:

image.png

loading="lazy" decoding="async"

参考文章: 现代图片性能优化及体验优化指南 - 懒加载及异步图像解码方案 

至此,发布到测试环境,安卓机表现很优秀,ios机有些会稍微快了点,有些依旧很慢。

测试说:继续优化!

OK,fine。

参考文章:详解JS图片预加载的方法

如下:

preloader加载图片

addLoadEventonload阶段加入事件。



function preloader() {  

    if (document.images) {  

        var img1 = new Image();  

        var img2 = new Image();  

        var img3 = new Image();  

        img1.src = "http://domain.tld/path/to/image-001.gif";  

        img2.src = "http://domain.tld/path/to/image-002.gif";  

        img3.src = "http://domain.tld/path/to/image-003.gif";  

    }  

}