Hacker News new | ask | show | jobs
by jcampbell1 4697 days ago
The important trick to know is, don't mix DOM modification with DOM measurement. Measuring the DOM is what triggers the DOM modification queue to get flushed.

if you do something like

   $('a').each(function(k,e){
      $(e).append('<span>' ...);
      var width = $(e).width()
      // do something with the width;
   }
If you have code like the above, it is going to cause a repaint on each iteration. If you unroll it into three separate loops, one that does dom modification, one that does dom measurement, and another that does modification, then you will drop the number of repaints from potentially 100s to just 2.
1 comments

It does not trigger repaint on each iteration.