[thelist] NN4.7 not showing my Home page/images

Keith Davis cache at dowebs.com
Mon May 28 13:27:01 CDT 2001


sfmalo wrote:

> Two questions:
> 1) You suggested placing the external js script tag in the body section. Is
> that in addition to or instead of placing the same script file tag in the
> head section?

That's instead of. 

> 2) Also, re the decision to split the script file into two (placing one new
> file tag in the head and the other in the body): I am going to be using this
> same script for a site that will be loading far more images (42 nav images
> vs the 24 on my site) for the navigation. Then, would it be wise to split
> the file into two?

Putting a javascript src tag in the body will slow down the loading and
renduring of the body. Therefore, the more images in that body, the more
noticable that effect will be. So, yes, I would suggest splitting it
with more images. But, more important, the browser can call, assemble
and display one image while simultaneously calling and assembling other
images. It cannot do that when it encounters an external js file tag in
the body, instead it stops all other processes while it calls, assembles
and examines the js file for document.write functions. Even a small 1K
js file will therefore have a speed of page renduring effect out of
proportion to it's size compared to a similar sized image. Therefore, it
is wise to put only javascript that is necessary for an onload event in
the body while putting all other javascript in the head. 
 
>  I'm not exactly clear what instructions should go in which file. I now have
> 1) an opening "if(document.images)" statement followed by the variables, 2)
> a second "if(document.images" statement followed by "for" and three "new
> Image" references, and 3) three "function" statements. 

Looking at your script, remotecarat.js, I see a logical paradox. The
onload event first creates a variable "loaded" by setting it's value to
1, it then calls the function clic(1). Function clic() test to see if
the body has loaded by testing for "loaded". However, function clic(),
depending on net traffic, sometimes does not yet exist in the script
engine. I believe that's why the initial rollover on your "home" nav
image is erratic. The paradox is that the function is asking if the body
has loaded, when we really need the body to be asking if the function
has loaded. Well rather than ask that question, just put the clic()
function in the body and force it to load before the body finishes
loading. You also have two functions that are called by mouse movements.
That may happen before the page and/or the script has loaded (you know
how surfers are!). In some browsers calling a function that does not yet
exist will cause an error. So, you want to also guarantee that those
functions are loaded asap. 

Ah, but you still want a straight answere to your question, right? Well,
we're not done. Those two if(document.write) blocks set up the array
that the clic and mousey funtions use. And if that array does not yet
exist when those functions are called you'll get an error. The straight
answere: put it all in the body.

The "loaded" test in the script shows good form on the part of the
author by anticipating a misbehaved surfer clicking or mousing before
the page has loaded. If the script is part of the page, this plays it's
role since the functions will indeed be loaded before the page. The
problem arises by putting the script in an external file which may load
later than the body. 

You're in good company here Sharon, I see this happening a lot on NBCI. 

>Am pretty new to
> javascript so please forgive me if I have not used the correct terminology
> here.

Don't worry about that! Only Jeff and Joe know for sure what the correct
terminologies are :)

> You are due at least three dodos and a crate of apples for free for this
one.

What? Apples attract dodos? I can get apples. Consider the score a tie!

keith




More information about the thelist mailing list