Hi, > > variable names. You can e.g. do that by encouraging people to use Plugin > > names like java packages, e.g. "org.jquery.ajax". > > Exactly! And furthermore if you use a corresponding directory > structure i.e. /jslib/org/jquery/ajax.js then you should eliminate > collisions right off the bat.
That is exactly how jsPax searches for its packages. > It also seems the OpenAjax approach assumes an HTML page with a large > number of script tags. In my apps I use two: > <script src="/jslib/jquery-latest.pack.js" ...></script> > <script src="/jslib/jqjsan.js" ...></script> // the jQuery port of > JSAN i mentioned in a previous post > <script type="text/javascript" ...> > $.jsanUse('com.myapp.controller'); > </script> I simply use <script src="/scripts/package.js" type="text/javascript"></script> <script> $package.packageBase = '/scripts/packages'; $using('com.myapp.controller', function() { // ... do something when library has finished loading. }); </script> > And for the sake of example the file /jslib/com/myapp/controller.js > would look something like: > if (typeof self != 'undefined') { > if (typeof com == "undefined" ){ com = {};} > if (typeof com.myapp == "undefined" ){ com.myapp = {};} > if (typeof com.myapp.controller == "undefined" ) > { com.myapp.controller = { > [...] > }); > > } else if(typeof $.jsanUse != 'undefined'){ > $.jsanUse('com.myapp.controller'); > } else { > throw new Error("com.myapp.controller does not support your > platform"); > } In my case it is $using('jQuery', function() { $package('com.myapp.controller', { // ... the com.myapp.controller package. }); }); > Note that functionality like com.myapp.errorClass is loaded on demand > only if and when I need it. That is exactly what jsPax is for. Have a look at jspax.org. > This keeps the initial footprint small. Last time I looked at JSAN, the initial Footprint for jsPax was a lot smaller. As I can see from your Script-tags, you are loading jQuery as part of the initial Footprint as well. For me jQuery is just another package. > Since the namespace is created when the package is loaded any further > calls to $.jsanUse('com.myapp.errorClass') will not reload the files > as it checks for the namespace first. jsPax can even find out that a file has already been requested but has not finished loading. That way you can do something like this: $using('jQuery', function() { // jQuery is available here }); // jQuery is not available here $using('jQuery.ajax', function() { // jQuery.ajax needs the package jQuery as well. // here bth packages are available, but jQuery will only be loaded once. }); > Overall your jslib may > contain a larger filesize but you will only be loading small bits > spread over the time your app is being used. Yes. I use things like that: $using('jQuery', function() { $(function() { $('#myelem').click(function() { $using('some.other.package', function() { // the other package will be loaded after the // element has been clicked the first time. }); }); }); }); Christof