Does using a document fragment really improve performance?

后端 未结 7 1445
臣服心动
臣服心动 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:32

    The jsperf from wolfram77 contains an additional for loop in the non fragment example which is the main cause for the performance difference, not the DocumentFragment. By removing this additional for loop you can achieve the same result but the performance is completely different:

    Example on jsperf.com

    So I still don't see a performance benefit on the scripting part but there might be one in the browser when it has to repaint for each appended element.

提交回复
热议问题