straight html or dom generated html objects faster?

Discussion in 'Javascript' started by anagai, Jan 2, 2006.

  1. anagai

    anagai Guest

    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?
    anagai, Jan 2, 2006
    #1
    1. Advertising

  2. anagai

    Guest

    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="block";; after having
    created 'popup' with static HTML earlier will be faster than
    document.appendChild(popup);
    , Jan 2, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Beza
    Replies:
    2
    Views:
    401
    Kevin Spencer
    Jun 27, 2003
  2. Jordan
    Replies:
    2
    Views:
    2,513
    Jordan
    Feb 10, 2004
  3. Joe Coppola

    Straight ASP problem

    Joe Coppola, Jun 14, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    412
    Joe Coppola
    Jun 14, 2004
  4. .Net Sports
    Replies:
    2
    Views:
    727
  5. Replies:
    11
    Views:
    187
Loading...

Share This Page