Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 412345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:04:34+00:00 2026-05-12T18:04:34+00:00

I’m wondering what is the right way to do dom insertion of complex elements.

  • 0

I’m wondering what is the right way to do dom insertion of complex elements.

Until now, (with jQuery) I used to first build my element and to insert it once finished. I thought that it was the most efficient, since DOM access is costly performance-wise.

But with native js, I read that to avoid memory leaks, each new dom node should be inserted in the dom right after its creation.

Our intranet says :

Dom insertion order
Pay attention to DOM insertion order: never append a child element to a root element before the root is itself appended to the DOM.

var root = document.createElement("DIV");
var child = document.createElement("DIV");

// THIS IS WRONG

root.appendChild(child);
document.body.appendChild(root);

// THIS IS CORRECT

document.body.appendChild(root);
root.appendChild(child);

I found online this page which basically explain the same thing (under the Cross-Page Leaks section) :
http://www.codeweblog.com/javascript-memory-leak-on-the-collation-of-draft-issues/

Does that mean that there is an opposition between performance and leak-prevention ?

Should new DOM elements be created and manipulated as string before to be inserted ? How are js libraries solving this ? Is DocumentFragments the miracle solution ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:04:34+00:00Added an answer on May 12, 2026 at 6:04 pm

    The advice you quote is almost certainly inspired by an article written by a member of the IE Team about memory leaks in (unsurprisingly) IE, specifically the section concerning the “DOM Insertion Order Leak Model”.
    Two points are worthy of note:

    1. The article was written in 2005 specifically to address leak issues in IE 6 – IE 7 hadn’t even been released at the time;
    2. It is solely concerned with IE; there is no suggestion that any other browser suffers from the same problem.

    According to a 2008 post on the IE Team blog (under the subheading “Memory Management Improvements”), IE 7 included improvements to prevent such leaks persisting for the lifetime of the browser window, and IE 8 contained further improvements to hopefully eliminate any need to be concerned about this matter.

    So the question you need to ask is: how much of an issue is IE 6 for you? At the end of the day, order of DOM insertion should never have been something to be concerned about, but if (for example) you are working on an intranet app that will be used on IE 6 for some time to come, then you should take note of the points in the 2005 article. If you have the luxury of knowing that IE 6 is scarcely a blip on the radar for your app, then don’t worry about any of it.

    Oh, and note that appending everything to the parent before appending the parent to the page will provide better performance: rather than having to do a reflow and repaint each time a new child is added, the browser can do one reflow and repaint when everything arrives in one tidy chunk.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have text I am displaying in SIlverlight that is coming from a CMS
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.