Web Analytics Made Easy -
StatCounter speed of document.write - CodingForum

Announcement

Collapse
No announcement yet.

speed of document.write

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • speed of document.write

    Hi,

    I was wondering whether placing an entire html-page in javascript-mode (i.e. document.write("<HTML>\n"); document.write("<HEAD>\n"); etc. etc.) will have any negative effects on the loading-time of the page. In other words how fast does javascript process the document.write, comparing to plain html?

    Thanx Michiel

  • #2
    Yes that will definitely slow you down. Whenever I write large chunks of code to a document, I write it all to a variable first then just write the string to the document, using the write method just once.

    example (mypage is the page I'm writing to):

    var str = ""
    str += "code here etc....
    str += "continue till done....

    then
    mypage.document.open();
    mypage.document.write(str);
    mypage.document.close();

    That will make a world of difference compared to continually calling the document.write method.
    hope that hels

    Comment


    • #3
      i agree

      boywonder is right!

      It is indeed better to put your code into a variable.
      Moreover it is clearer to check if you want to change something in the code.

      use that way.

      Comment


      • #4
        using document.write() to do your whole page, whether you use a variable or not, will be slower than plain html. probably, noticeably slower.
        bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

        i am a loser geek, crazy with an evil streak,
        yes i do believe there is a violent thing inside of me.

        Comment

        Working...
        X