[Javascript] downloading javascript

Laurent Goffin lgoffin at wonderweb.net
Sun Jul 13 04:22:51 CDT 2003


>3. Could the html be so small that the javascript does not have time to download?  The javascript is 9kb.
>4. How is a page loaded?  ie starts with the html and as soon as external import is found, downloads the javascript?  when the end html is found does all downloads stop?

Right,

there are chances that ur javascript is not yet loaded when the HTML page call for the functions...
I dont mean not yet downloaded but when the HTML page is loading, the browser interpret HTML and create a DOM out of this. In the mean time, he is downloading the JS external file and when the file is dlowloaded or present in the cache, the browser is interpreting all functions in order to make them available by the page.

For instance, when the BODY of your page is calling on onload event a function in ur external JS, it's possible the JS is already downloaded but the function does not exist yet for the browser.

It's the same too when a JS function try to call an HTML object while the page is not fully loaded yet (check onreadystate event for this)

A solution to this : when u call the first function and this function does not exist yet, just call instead a function which is a timeout checking if the other function exist. When the function exist, just call it and stop timeout.

Thsi require of course the timeout function to be outside of the JS file...

Have a nice day

L. Goffin


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20030713/3b2bb0b6/attachment.htm>


More information about the Javascript mailing list