RES: RES: [Javascript] Including additional javascript files
Alex Robinson
latechjavascript at alex.cloudband.com
Mon Apr 4 16:34:03 CDT 2005
>If you?d tried the code you?d have seen that this function also works with
>nesting includes in other includes.
>Just put the function in the first include, so that the rest of the code can
>use it.
My apologies Allard.
You're quite right that it works.
http://www.fu2k.org/alex/javascript/javascriptjunk/js_include.html
This is probably exactly the technique I saw before - I just didn't
recognise it. I was, in my hot-headed way, thinking that the
document.writes would need to be explicitly placed within a script
tag inn the document or else the doc.writes would overwrite the
pre-existing content.
The method does have two down sides.
1. Every initial file that needs to do the include thing will need
the Loadscript function.
Of course, it's somewhat churlish of me to expect this functionality
for free (though why the hell doesn't javascript have includes as
part of the core?) and it's really just a one line copy and paste job.
2. It won't work if the document is xhtml served as xml
The fix for that situation I guess is would be to return to the idea
I mentioned before of inserting the script element via the DOM.
Last observation is that some browsers halt execution of the current
js file while loading the next one and others carry on regardless.
This shouldn't be a problem in real world usage if care is taken, but
I can foresee it causing head scratching problems late at night
Apologies once again Allard, and thanks aplenty :)
More information about the Javascript
mailing list