javascript - Faster to append or create html elements before? -- JQuery -
i trying make application faster. want elements appear when ajax request has succeeded. faster create elements append when request has succeeded, or faster create html element in actual html , insert content in element .html?
according jsperf: plain old innerhtml
beats .html()
(and .html()
beats .append()
).
however according jsperf: dom
beats innerhtml
.
so, might want documentfragment
, specified in dom1 , supported in ie6 (so there no reason not use it).
since document fragment in memory , not part of main dom tree, appending children not cause page 'reflow' (computation of element's position , geometry). consequently, using document fragments results in better performance.
john resig did nice write-up here , concludes:
a method largely ignored in modern web development can provide serious (2-3x) performance improvements dom manipulation.
you might want combine of techniques per case want optimize.
hope helps!
Comments
Post a Comment