页面性能优化的几种方法

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/"> 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值