By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,826 Members | 2,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,826 IT Pros & Developers. It's quick & easy.

straight html or dom generated html objects faster?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a

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.