469,282 Members | 1,749 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

straight html or dom generated html objects faster?

Im wondering if generating html objects such as tabels and rows in
javascript is faster than typing the html directly? Seems when you do
it in javascript you have to download alot of code and would slow down
displaying the page. while if you just type the html, it requires less
bandwidth and display faster?

is parsing html to display in browser slower than doing it through dom
to display the same html objects on the page?

Jan 2 '06 #1
1 1706

anagai wrote:
Im wondering if generating html objects such as tabels and rows in
javascript is faster than typing the html directly? Seems when you do
it in javascript you have to download alot of code and would slow down
displaying the page. while if you just type the html, it requires less
bandwidth and display faster?
"download a lot of code" is a pretty wrong idea. The code is there. If
the browser creates a line of a table from <tr>..</tr>, it calls the
very same createElement() that you would call to do so from Javascript.

The answer is ambigious though, because while calling DOM functions
from JS to create elements is faster because of skipping the whole
XML/SGML parsing, it is at the same time slower because of launching
userspace javascript program which takes up CPU space. Whether the
speedup or slowdown is stronger depends on lots of factors.

Obviously sending <script>for(var
i=1;i<10000;i++){document.appendChild(createNode(' br'))}</script> will
take less bandwidth than sending 10000 BR tags. Which will take shorter
is a different matter though,
is parsing html to display in browser slower than doing it through dom
to display the same html objects on the page?


The objects to be displayed must pass both steps. First to be parsed as
HTML, then the resulting tree rendered as DOM. Likely the former is
slower, but for static HTML both are needed. If you generate elements
with a script, you skip HTML parsing, but then there's whole script
parsing, compilation, checking, execution and it takes time too.
Generally createElement will be faster than document.write() or
..innerHTML (and more reliable too), but most likely
document.getElementById('popup').style.display="bl ock";; after having
created 'popup' with static HTML earlier will be faster than
document.appendChild(popup);

Jan 2 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by catchanu | last post: by
7 posts views Thread by Alan Silver | last post: by
10 posts views Thread by George | last post: by
26 posts views Thread by webrod | last post: by
3 posts views Thread by NullQwerty | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.