1、图片优化
(1)减少图片的像素点
(2)减少图片每个像素显示的颜色
2、DNS预解析
<link rel="dns-prefetch" href="//interview.html5.wiki">
3、节流函数
const throttle = (func,wait=50)=>{
//上一次执行该函数的时间
let lasttime = 0;
return function throttle(...args){
//获取当前时间
let now =+ new Date()
//当当前时间大于上一次执行该函数的时间时,函数执行
if(now-lasttime>0){
lasttime = now
func.apply(this,args)
}
}
}
4、防抖函数
const debounce = (func,wait=50)=>{
//设置一个定时器
let timer = null;
return function debounce(...args)
//若timer不为0,则清空timer
if(timer){
clearTimeout(timer)
}
//延迟执行用户传入的方法
timer = setTimeout(()=>{
func.apply(this,args)
},wait)
}
5、预加载
<link rel="preload" href="http://www.html5.wiki/">
6、预渲染
<link rel="prerender" href="http://www.html5.wiki/">