衡量屬性和布局的消耗代價
1.合理安排選擇器(選擇器瘦身);
2.高消耗屬性?--》繪制前需要瀏覽器進行大量計算:
border-raduis,transforms,box-shadows,transparency,cssfilters(性能殺手)
css的優化:避免過分重繪,避免過分重排(瀏覽器重新計算布局位置和大小),慎重選擇高消耗的樣式;
瀏覽器重新計算布局位置與大小
常見的重排元素:
width,height;padding;margin;display;border;top:position;font-size;font-size;text-align;
避免過度的重繪:
常用的重繪元素:
color,borrder-style,visibility,backgorund,text-decoration,bavkground-image,background-repeat,borddr-radius,outline-color,box-shadow,background-size;
css will change:思路是,把GPU利用起來(在移動端要慎重選擇)
requestAnimationFrame:讓視覺更新按照瀏覽器的最優時間來安排計劃:60fps,取代setTimeout和setInterval hack
避免過分重排(瀏覽器重新計算布局位置和大小)
搜索w3c的性能優化新規范
用測試數據判斷優化策略