当前位置:网站首页>image 多图片页面的优化方式
image 多图片页面的优化方式
2022-07-21 05:06:00 【bug调教师】
1,使用懒加载,未出现在页面的图片等到出现在页面再进行加载出来
// html
// data-src 自定义属性
// js
var images = document.querySelectorAll(‘img’);
// images.forEach((image)=>{
// let imgtop = image.getBoundingClientRect().top();
// if(imgtop<window.innerHeight){
// let dataSrc = image.getAttribute(‘data-src’);
// image.setAttribute(‘src’,dataSrc);
// }
// })
let callback =(entries)=>{
entries.forEach(entry=>{
if(entry.isIntersection){
const image = entries.target;
let dataSrc = image.getAttribute(‘data-src’);
image.setAttribute(‘src’,dataSrc);
observer.unobserve();
}
})
}
// IntersectionObserver 浏览器构造函数
let observer = new IntersectionObserver(callback);
images.forEach(image=>{
observer.observe(image)
})
2,使用工具将图片进行无损压缩
地址:https://www.yasuotu.com/
3,小图片转base64,减少网络请求,大图片不要转base64,因为包会变大,小图片影响不大
4.webpack 打包压缩
地址:https://webpack.docschina.org/plugins/image-minimizer-webpack-plugin/#root
边栏推荐
猜你喜欢
[C语言] 平淡的日子里泛起光 初阶最后的战役
如何通过IP共享文件
三子棋
自定义MVC框架实现
[c language] selecting the loop can also play the code like this to show the country of light
解决safari浏览器拦截window.open
10.【file的打开格式及其判断是否打开】
Doing questions leads to the understanding of getchar ()
12.【I/O流get()与getline()与put()函数】
Dynamically listen for the height of DOM elements
随机推荐
js运行机制
PCL运行时ucrtbased.dll引发的异常
矩阵求导常用公式(避坑)+矩阵的模和矩阵的绝对值的求导
C language to achieve three chess games - pattern open version(
16.【字符串的赋值以分号为结束】
Small game items - Gobang game
Vs, MATLAB, leetcode annotation shortcut key
D. Insert a progression (Mathematics)
不拉扯了 不拉扯了 碎碎念 下
Self taught programming for more than 80 years, these private practical tools & learning websites have accompanied me to the present. I must collect them and double my learning efficiency - Website
今天不拉扯了 不拉扯了 碎碎念 上
开发模式下热更新 加快开发环境代码更新
受控组件和非受控组件的区别
SimpleDateFormat正确使用
Deep analysis of string -- strlen & strtok
User defined MVC addition, deletion, modification and query
Codeforces-479A
第四局 匹配 上 数据分析
Deep analysis recursion
[C language function array] take away my last thoughts!