How Bad is DOM Interaction Really?
andyshora.com
andyshora.com
Reflows are very expensive. So are repaints. Chrome dev tools will allow you to detect issues with both of those.
Just looking at their implementations in WebKit should tell you why:
https://github.com/WebKit/webkit/blob/master/Source/WebCore/...
https://github.com/WebKit/webkit/blob/master/Source/WebCore/...
The case is extremely misrepresented indeed.
DOM Lvl 4 even features GC! Can we not see why this is a bad idea?!? Keyboard bindings also do not belong in a "standard". I wish this would get more attention by serious developers, but I think that most people who know better wouldn't care and aren't interested in understanding and digging into a lame standard. It's a land grab, only enterprises can and will ever be able to implement it correctly and completely, as the standard spreads to consume more of the user's space.
Here are some people who agree with me:
http://www.adamcrume.com/blog/archive/2009/12/23/the-java-do...
http://programmers.stackexchange.com/questions/147451/whats-...
To your friends that agree with you from 2009, use `querySelectorAll` for a non-live NodeList, assuming he has kept up with JS actually having evolved and converging on standards.
I bet you flip your lid, too, to learn your server-side-only dystopia is running on top of JS (Node) services.
You have nowhere to begin because I'm absolutely right. The DOM is klausterfokken.
You absolutely can touch the DOM, but should do so through and interface that manages or eliminates repaint and reflow.
Making single frame of JS code to run fast is cool and dandy, but eventually browser will have to make freeze and do reflow+repaint. Eventually it will make profiling harder, think about caching .offsetHeight etc. properties. It does decrease script execution time, but it does not make your app to work faster.
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.http://learn.jquery.com/performance/
It's brief and quite informative.
Here I come html5!
Overall performance is terrible and varies widely between browsers. We either need a new standard or a DOM browser battle like what happened with JavaScript, bringing it from 100x to 3x of native.
So I'd add the caveat to caching jQuery selectors that standard premature optimization rules still apply.
Really the resize thing is sort of bs also because it is such an incredibly rare thing to handle (99% of all apps will never ever require handling resize except to test responsive designs)