Including other .js files from javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Catherine Lynn Smith

    Including other .js files from javascript

    I am trying to figure out the recommended way to include javascript
    'from' javascript. I found some references that say to just write a
    'script' tag to the document, but I am curious about the parse order
    for this.

    i.e., if I have a 'core set' of routines that I prefer to store in a
    seperate file due to the fact they are used in multiple pages, it
    makes more sense to call them in from the javascript that needs them,
    but if I do so with a 'write' to the document, are they parsed before
    any additional code in the existing .js file?

    The idea being - since these would be core functionality routine
    libraries, the page-specific code I include via the HTML will need to
    have any subroutines and functions available to work properly.

    Any help and comments are greaty appreciated.

    KL
  • Catherine Lynn Smith

    #2
    Re: Including other .js files from javascript

    OK, an addendum to my earlier post/question. I was able to find out
    that a document.writel n was sufficient to include files with a
    standard HTML script tag including those fulfilling needs of dependant
    functions. But this raises another issue now.
    Is it going to hurt anything if the file is included twice, or is
    there any way to check within the code for the existence of a function
    before doing the document.writel n('<script....> ') stuff? Or should I
    handle this by defining a variable somewhere in the 'library' itself
    and testing against that?

    KL

    Comment

    Working...