Is there a best practice in dealing with javascript dependen


#1

As I’ve begun to work with several javascript libraries out there,
I’ve run in to some dependency issues that must have been solved by
others before.

For example, I’m trying to implement the jstree library from Laurie
Harper in to BundledResource. Breaking the ‘jstree’ javascript from
the sample html out in to its own file caused it to fail because the
browser now tries to load both behaviour.js and (my new file)
jstree.js at the same time–but jstree.js depends on the behaviour
library to work.

The only solution I’ve found appears to be in a library I bumped in
to from google, but I’m not sure it’s the best answer[1]. Has anyone
else seen something easier and/or more “standard”?

Duane J.
(canadaduane)
http://blog.inquirylabs.com/

[1] http://blog.metawrap.com/blog/
AutomaticDependencyResolutionForJavaScriptLibraries.aspx


#2

Duane J. wrote:

The only solution I’ve found appears to be in a library I bumped in to
from google, but I’m not sure it’s the best answer[1]. Has anyone else
seen something easier and/or more “standard”?
The only way I’ve found of cleanly dealing with dependencies is by doing
something like this:

function include(scriptname){
document.writeln(
‘’);
}
var global_docs = {};
function require(scriptname){
if(!global_docs[scriptname]){
include(scriptname);
global_docs[scriptname]=true;
}
}

then you can call require(‘behaviour.js’) from jstree. This is probably
horribly wrong in some respect, but it works for me so far…


#3

On Jan 11, 2006, at 3:31 AM, Alex Y. wrote:

The only solution I’ve found appears to be in a library I bumped
var global_docs = {};

Alex

Actually, I recently discovered this technique being used by the
scriptaculous library, so it can’t be that far off :wink: Can anyone
else confirm that this is the best way to go? Does using AJAX to
include libraries have any advantage over this method?

Thanks,
Duane J.
(canadaduane)
http://blog.inquirylabs.com/