jQuery 對效能的調整...

TwitterjQuery 1.4.2 換到 1.4.4 以後,發現在捲頁時的效能變得很差:「About that slowness on Twitter…」。

這件事情讓 John Resig 在他的 blog 上發表了一篇文章,發現原因在「$something.find(".class")」這種用法,成為壓死駱駝的最後一根稻草:「Learning from Twitter」。主要的原因是 querySelectorAll(".class") 比起 getElementsByClassName() 慢了一些,而 Twitter 的寫法會使得這個 function 的效能明顯放大到影響整體效能的程度...

文章以及 comment 有給一些建議 (cache selector 與針對 scroll event 的處理),記起來以後應該會有幫助...

Leave a Reply

Your email address will not be published. Required fields are marked *