views:

37

answers:

2

I know that certain changes to the DOM of a web-page (by JavaScript) will result in the rendering engine calculating a new layout for rendering (not sure if my terminology is correct).

I have a process that updates data fairly frequently with comet style long-polling requests. Some of these updates are fairly frequent. I know that a good general rule of thumb is to remove the target DOM element, make the necessary changes, and then put it back into the DOM (so you only get hit twice with the re-render), but I wasn't sure if you only replace the inner text of an element if you incur the same hit. In my case, I am updating the content of some table-cells, that are just text (not wrapped in spans or divs).

+1  A: 

Any time something changes in the DOM it triggers a Repaint and Reflow. Even if you're just changing text.

indieinvader
+1  A: 

yes it will be just like you want to be.

For example: you have a div with id="div" and its html setted to text of 'Lorem'

var div = document.getElementById('div');
div.innerHTML = 'Lorem Ipsum Dolor'

then you will see the div's innerHTML to be setted 'Lorem Ipsum Dolor'. this is called document reflowing.

Lorenzo

Lorenzo
that's actually what I *didn't* want it to be :) I was trying to figure out if I could speed things up by selectively updating innerText as opposed to rebuilding high-up DOM structures.
Matt
I could not understand you. If you be more clearly, I want to be help you as well :)
Lorenzo