[Web-SIG] JavaScript libraries

Ian Bicking ianb at colorstudy.com
Mon May 2 21:22:10 CEST 2005


mike bayer wrote:
> what kind of features are you looking for in these javascript libraries ? 
> I see sarissa is just the XMLHttpRequest method tied to writing the guts
> of DOM objects, and then some more elaborate DOM inspection methods that
> seem less useful.
> 
> it seems to me that the "server-neutral" javascript part of AJAX is
> nothing more than a single function to connect an XMLHttpRequest and feed
> it to a callback function, and perhaps a couple of generic callback
> functions, i.e. "execute the javascript returned" and "write the HTML
> returned into this DOM element".  everything else is specific to a
> particular application and/or server side approach.

I agree that this is pretty much it.  There's a few ways you might make 
the request -- ad hoc XML, a normal request with HTTP/url-encoded 
fields, XML-RPC, JSON.  But they are all largely equivalent.  And then a 
few helper methods, to make things like "call this server method and 
write its output to id X" easy to express.  Underlying this is some 
cruftiness, compatibility and whatnot, but the core is pretty small.

jsolait, which is the only library I've tried to use enough to have an 
opinion on, is relatively simple.  My only criticism is that it seems to 
try to be too clever, when Javascript doesn't always support that 
cleverness.  For instance, there is a server proxy object similar to 
xmlrpclib.ServerProxy; but because Javascript doesn't have a __getattr__ 
equivalent you have to enumerate all the methods.  At which point it 
wouldn't be that much harder to simply create multiple proxy objects. 
The module stuff is also a bit difficult; it does keep the namespace 
clean, but "import" doesn't work well at all, and I doubt that is 
resolvable.  And some things, like an equivalent to Python's string % 
operator, seem unnecessary to me.  But then, it's not like they hurt.

Mostly what I personally seek is a limited set of documented 
functionality that covers what I need, and does so reliably; something 
that covers over all the crufty corner cases, which are so easy to fall 
into in Javascript because there's lots of stuff that *does* work 
reliably, but many problem cases you can't predict without experience. 
I'm hoping to get the benefit of other people's experience through code 
and documentation.

> I went and took the single connection function from the Sajax demo and
> built a bunch of stuff off of that... once you can connect and get data,
> document.getElementById('foo').innerHTML = <blah> can draw anything
> anywhere you want.

Incidentally, the Rails people felt pretty strongly that innerHTML was 
the way to go, because DOM manipulation is hard to maintain, and 
innerHTML is very consistent across browsers.

-- 
Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org


More information about the Web-SIG mailing list