PDA

View Full Version : speed of document.write


Michiel
07-01-2002, 09:19 PM
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

boywonder
07-01-2002, 10:53 PM
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

foss
07-02-2002, 11:29 AM
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.

joh6nn
07-02-2002, 01:02 PM
using document.write() to do your whole page, whether you use a variable or not, will be slower than plain html. probably, noticeably slower.