Forum Moderators: open

Message Too Old, No Replies

Include external javascript file within a external javascript file?

I assume some document write method is required

         

dannyboy

5:21 am on May 8, 2004 (gmt 0)

10+ Year Member



I use the following javascript calendar script:
[dynarch.com...]

It requires three external javascript files to operate:

<script type="text/javascript" src="calendar.js"></script>
<script type="text/javascript" src="lang/calendar-en.js.js"></script>
<script type="text/javascript" src="calendar-setup.js"></script>

Is there anyway I can call one external javascript file...
<script type="text/javascript" src="calendar-ALL.js"></script>

and within that single external file (calendar-ALL.js) call the other three external javascript files?

I remember reading about a method to include an external javascript file within another external javascript file, but my searches turned empty.

Finally, does using such a method have any downside/bugs, such as caching problems?

moltar

5:26 am on May 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hmm.. all I can think of is using

document.write("<script type=\"text/javascript\" src=\"xyz.js\"></script>");

in the main file to call other 3. Haven't tested it though...

dannyboy

5:36 am on May 8, 2004 (gmt 0)

10+ Year Member



moltar, your method works. Thanks.

I hope this thread doesn't die until someone touches on any potential downside/bugs using such a method would cause.

john_k

6:10 am on May 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The only downside I can see is the latency in fetching the secondary set of files. Normally, as a browser parses the original html source, it will begin sending requests for external resources as it encounters them. With the method you have outlined, the browser will also need to fetch, parse, and begin executing your calendar-ALL.js file before it will know enough to request the other three.

Bernard Marx

8:34 am on May 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



..and there's now this:
[webmasterworld.com ]