W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2015

Re: oldNode.replaceWith(...collection) edge case

From: Boris Zbarsky <bzbarsky@mit.edu>
Date: Tue, 20 Jan 2015 22:23:12 -0500
Message-ID: <54BF1BA0.40704@mit.edu>
To: public-webapps@w3.org
On 1/20/15 6:45 PM, Glen Huang wrote:
> I vaguely remember document fragment is introduced just to reduce
> reflows. Looks like this best practice is obsolete now?

You don't have to use a document fragment to reduce reflows, as long as 
you don't query layout information between your DOM notifications.

There are some other things (e.g. maintaining DOM state of various 
sorts) a browser may be able to optimize a bit better with a document 
fragment.  Or not.

> So to recap, when you have the need to pass the context node as an
> argument along with other nodes, just use before() and after() to insert
> these other nodes? And even insert them one by one is fine?

I strongly suggest measuring to get an answer to this question.  The 
performance characteristics will depend on the browser, on the exact set 
of DOM features used on the page, and on the exact stylesheets used on 
the page.

That said, I would expect the difference between inserting a document 
fragment and inserting the nodes one at a time to be fairly small in all 
modern browsers in most situations.  Note all the weasel-wording.  ;)

-Boris
Received on Wednesday, 21 January 2015 03:23:42 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:27:25 UTC