[Javascript] Including additional javascript files

Paul Novitski paul at novitskisoftware.com
Wed Apr 6 11:06:41 CDT 2005


At 01:01 AM 4/6/2005, Alex Robinson wrote:
>Andrew Clover wrote:
>>On the other hand, IE/Mac works for me (A->B->C); version 5.2.3 on Mac
>>OS 10.3.
>
>How odd.
>
>I just checked to confirm. My IE/Mac 5.2.3 running under 10.3.7 definitely 
>does C->B->A for both remote and local files.


So... rather than lean one's weight on this particular detail, which 
clearly varies from one user agent to another and might vary further for 
others yet untested, it would seem that the safest way to code across 
nested includes is for each piece of code never to assume that any other 
external module exists and to look before leaping, e.g.:

function FunctionA
{
         if (FunctionB)
         {
                 do stuff
         }
}

...either checking periodically on a timer or, of course, waiting until 
window-onload to fire.

If you need to engage code before window-onload, and if nested includes 
depend on one another, I suppose you could design a central switchboard in 
which each included script sets a global flag when it wakes up.  Any 
function requiring others could check the flags before proceeding.

Aside, this ability of javascript to write its own includes while it's 
running is amazing when you think about it.  Unlike ASP/VBscript which 
processes all the includes in an early compile phase before the script 
starts executing and therefore can't accommodate conditional includes, 
javascript has the ability to examine itself, see what functions it's going 
to need, and insert includes accordingly.  This solves one of the biggest 
problems with subroutine libraries -- how do you download just the modules 
you need and not the whole bundle?

Regards,
Paul 





More information about the Javascript mailing list