Click to See Complete Forum and Search --> : What's faster? document.write vs. <iframe>
sunhawk
07-17-2003, 04:49 PM
Hello! This is my first posting here :-)
Some domains I host without PHP but I still try to
make maintainance comfortable. For example I put
some HTML of the navigation into a JavaScript with
document.write and just place this JavaScript into
all the HTML pages.
My question is whether a page loads faster if I write
all this document.write stuff or is it loading faster if
I put document.write("<iframe>... and use a new
HTML document for the actual HTML code?
Thanks for your help! Please excuse my poor English...
Greetings from Germany
sunhawk
fla5hba5h
07-17-2003, 04:54 PM
Good question. I'm not sure, but I would guess that the <iframe> would load slower since it needs a source page.
Charles
07-17-2003, 04:59 PM
The JavaScript method will be faster, but only on the browsers that support JavaScript. That would make your site inaccessible to that 13% of users who do not.
To consider the effective speed of either method you would have to add up the time it takes to load for each user. The IFRAME method would have some effective speed X but the effective speed of the JavaScript method would be infinitly long for 13% of users plus some speed Y for the rest, or simply infinity. For any speed X, infinity would be longer and, hence, the IFRAME is better and since the difference between any number X and infinity is also infinite the IFRAME method is infinitely better.
sunhawk
07-17-2003, 05:19 PM
Wow, thank you for your fast answers!
Concerning the number of people who don't use JavaScript
(I thought it was only three % or so) I would consider to
use both methods at once by placing the iframe-tag between
the JavaScript-tag.
Do you think the JavaScript version is still faster if I have
400 lines of HTML-Code included with document.write?
I mean, the browser will take its time to load the external
JavaScript like any image. Add the time the browser takes
to interpret the JavaScript-code. Will there be a threshold?
(I'm not sure if threshold is the correct English term for what
I want to say)
Many thanks,
sunhawk
mzllr
07-17-2003, 05:30 PM
Originally posted by Charles
The JavaScript method will be faster, but only on the browsers that support JavaScript. That would make your site inaccessible to that 13% of users who do not.
To consider the effective speed of either method you would have to add up the time it takes to load for each user. The IFRAME method would have some effective speed X but the effective speed of the JavaScript method would be infinitly long for 13% of users plus some speed Y for the rest, or simply infinity. For any speed X, infinity would be longer and, hence, the IFRAME is better and since the difference between any number X and infinity is also infinite the IFRAME method is infinitely better.
ummmm, what?
to answer your question, i use the javascript method as well on sites that i don't code in php. just like you described, you create a .js file that contains your html inside a document.write and then call that file from your parent page with <script type="javascript" src="file.js"></script>
i have had no problems with this and the pages load just as quickly as if you included all the html code in the parent document.
Charles
07-17-2003, 05:30 PM
1) The backup IFRAME element should be within a NOSCRIPT element and contain a link for those browsers that do not recognize IFRAMEs:
<noscript><iframe src="some.html"><a href="some.html">Navigation</a></iframe></noscript>
2) If we're talking about external JavaScript then yes, the JavaScript method is indeed slower.
sunhawk
07-17-2003, 05:49 PM
Two different answers. Hm?
@charles
I forgot about the <noframe> - the best solution :-)
@mzllr
That's what I thought at first, but I'm not sure anymore
since one of my file.js has 400 lines.
This is really a tricky one as in both methods external
files are loaded. I'd like to add that there also might be a differenz if file.js is in a table construction compared to
stand alone. Or is that outdated knowledge?