[jsr-314-open] An observation on where we should focus attention

Jim Driscoll Jim.Driscoll at Sun.COM
Thu Dec 17 13:58:29 EST 2009


On 12/17/09 9:57 AM, Dan Allen wrote:
> Speaking of jQuery and JavaScript libraries, one question that came up
> was how does the developer ensure that if he/she is using two different
> Ajax-based JSF 2 component libraries that use jQuery, for instance, the
> library is only imported into the page once? Is there any idea of using
> a registry of common libraries namespaces? This would pertain to
> @ResourceDependency on a UIComponent in two different component
> libraries, both referencing jQuery. We have this unification already
> with javax.faces:jsf.js.

I saw that comment as well.

But I'm not sure it's really that big a deal...

Let's break down what the problem is here, since I really see multiple 
problems:

1) You download the file more than once.  This happens once.  After 
that, it's cached on the user's browser.  That means that you have a 
performance hit on the first hit on the page.  After that, there's only 
a negligible performance impact.  The recommended way to really get 
around this is to aggregate all of the files on the page, full stop - 
I'd assert that a component library should offer documentation on doing 
so.  That's not really possible programmatically - the combinatorial 
effects are too unpredictable.

2) You load the file more than once, and the library is the same 
version.  For badly written libraries, this may cause errors.  In which 
case, I'd advise you that if the library has that bug, it probably has 
others.  Note that this problem also exists for certain valid usecases 
with JSF Ajax, so you're already in trouble - for instance, Ajaxifying a 
commandButton with an action attribute.

3) You load the library more than once, and it's of different versions. 
  Again, you're quite probably hosed, unless the library is written to 
handle that case (jsf.js is).  I'm not sure there's much we can do about 
that, regardless of what we do.

All three scenarios are very similar to problems that the portal guys 
already face, and which we've committed to looking at for 2.1 - so I 
hope that Alexander chimes in here.

We could provide a registration mechanism, but then we'd have to run a 
registry.  Please see the OpenAjax registry for an example of how hard 
that is to do in practice.

Or, we could offer a limited registry, matching just the big frameworks 
- such as the ones offered by Google for download.

Or we could just recommend that component libraries at least offer the 
capability of using the Google library API:

http://code.google.com/apis/ajaxlibs/

(Which reminds me, we need to have markup for external resources.  We 
don't, currently, which is a shame, and limits the ability of libraries 
to offer this as an option - filed as spec bug 706).

Of course, none of that solves anything for the stuff that uses the dojo 
or YUI dynamic loading stuff.

Jim




More information about the jsr-314-open-mirror mailing list