4 ms·
Yes but WHY don't the browser makers optimize for what seems to be this very common use case? Why does a third party library outperform them?
by EGreg 12y ago
Yes but WHY don't the browser makers optimize for what seems to be this very common use case? Why does a third party library outperform them?
- mynegation 12y agoBecause when your code changes DOM, browser does not know whether you are going to stop at it for now, or do something else, so it has to re-render. In React you explicitly request application of virtual DOM changes to real DOM once you are done.
- jonathancreamer 12y agoGreat explanation.
- blktiger 12y agoIn theory they could add some new methods to the DOM api to allow for this, but it would be non-standard and currently none of the browsers have it. Something like this maybe? batchDomChanges(); ... dom changes here ... flushDomChanges();
- yblu 12y agoOr use fastdom[1], which batches reads and writes to reduce layout thrashing. [1]: https://github.com/wilsonpage/fastdom https://github.com/wilsonpage/fastdom
- zkhalique 12y agoWell I thought that is why there is requestAnimationFrame.