Does using a document fragment really improve performance?

后端 未结 7 1333
臣服心动
臣服心动 2020-11-30 01:57

I\'ve got a doubt regarding performance in JS.

Say, I\'ve got the next code:

var divContainer = document.createElement(\"div\"); divContainer.id=\"co         


        
相关标签:
7条回答
  • 2020-11-30 02:33

    In my experience dom operations usually happen only after call stack is empty. If I put lot of dom operations in the loop, browser just freezes for some time and then displays everything at once. You can break the stack by using setTimeout to display result more frequently if you want. For this reason I believe that both methods should perform similarly. This is actually very strange sometimes, because if in one stack you change some element you will never see its state before the change (had this problem with progress notification object which innerHTML was never updated during the loop - just starting status and then final).

    0 讨论(0)
提交回复
热议问题