const observer =newPerformanceObserver((list)=>{for(const entry of list.getEntries()){
console.log(entry)}})
observer.observe({entryTypes:['longtask']})
见面可见性的状态监听,代码如下所示:
let vEvent ='visibilitychange';if(document.webkitHidden !=undefined){// webkit prefix detected
vEvent ='webkitvisibilitychange';}functionvisibilityChanged(){if(document.hidden || document.webkitHidden){
console.log("Web page is hidden.")}else{
console.log("Web page is visible.")}}
document.addEventListener(vEvent, visibilityChanged,false);
判断当前网络状态,代码如下所示:
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;var type = connection.effectiveType;functionupdateConnectionStatus(){
console.log("Connection type changed from "+ type +" to "+ connection.effectiveType);
type = connection.effectiveType;}
connection.addEventListener('change', updateConnectionStatus);
一、Web 性能优化进行 Web 性能优化,因为性能是 Web 网站和应用的支柱,流量、搜索、转换率和用户体验的关系。寻找性能瓶颈,如下所示:了解性能指标,多快才算快利用测量工具和 APIs优化问题,重新测量迭代移动端挑战多,如下所示:设备硬件、网速、屏幕尺寸、交互方式用户更缺少耐心,大于 3 秒加载导致 53% 的跳出率持续增长的移动用户和移动电商业务二、性能指标和优化目标性能优化加载,如下所示:理解加载瀑布图基于 HAR 存储与重建性能信息速度指数 Sp