Server-side integration: Posts

Error handling in javascript

I was helping someone today with their javascript and they asked me about how and when I manage errors in the classes and functions that I write. I wrote him back an email which I think actually could be useful to others, so here it is.

There are three types of error handling that I use:

  • Graceful: if possible, just ignore the error and continue with some default state or without a meaningful value
  • Debug: throw a warning to the dbug.log method but continue otherwise
  • Break: Either explicitly throw an error or (more often) just let the error that is thrown at runtime be thrown

| Read the rest »

GWT Conference: December 3-6, 2007

via Ajaxian:

Addison-Wesley and Prentice Hall are putting on a conference dedicated to GWT on December 3-6 in San Francisco.

Much more detail in the blog post there.

Localizing the CNET JS code

The CNET JS code includes references to various assets - images and a few css files and at least one flash (swf) file. I include references in the javascript so that these things "just work" when you use them.

First and foremost, our libraries are designed for us to develop with, and making that process easy is our main concern. The problem is when you want to use these scripts somewhere other than CNET (or for local development).

Well, now you can. Just download the assets here:

http://code.google.com/p/cnetjavascript/downloads/list

Then use http://cnetjavascript.googlecode.com/svn/trunk/setAssetHref.js to set the location of the assets. Voila.

CNETAPI.js, ObjectBrowser.js

Hey gang,

Two new classes in the CNET libraries today.

CNETAPI.js

The first, CNETAPI, is probably not going to be very interesting to those of you reading this who don't work at CNET. Basically, this class makes it super-duper easy to get stuff out of our REST API. For example:

JavaScript:
//you have to do this only once on your page
//this is my dev key; get your own!
new CNETAPI(19926949750937665684988687810562);
//now our request:
new CNETAPI.TechProduct(32069546).chain(function(){
  dbug.log("got the Ipod, here's the data: ", this.data);
  alert(this.data.Name + ": " + this.data.EditorsRating.$);
});
//you have to do this only once on your page
//this is my dev key; get your own!
new CNETAPI(19926949750937665684988687810562);
//now our request:
new CNETAPI.TechProduct(32069546).chain(function(){
dbug.log("got the Ipod, here's the data: ", this.data);
alert(this.data.Name + ": " + this.data.EditorsRating.$);
});

drag to resize


Pretty snazzy, eh? Props go to Hunter Brown who wrote the guts of this class. I (Aaron) added some flare. More details and examples in the wikitorial.

ObjectBrowser.js

I'm working on some CMS tools for selecting options out of a tree (think genres/ontology) and I needed a tree browser. So I wrote a generic one that can be used to explore just about any kind of javascript object. Rather than paste in a lot of detail here, I'll just point you towards the wikitorial.

Building and compressing js libraries

We're working on an internal build system here at CNET that is a mixture of things like Mootools download builder and Dean Edward's /packer/ so that we can quickly include just the javascript that's needed on a page.

Today's post at Ajaxian shows that we're not the only ones working on such a thing. Our solution though will likely be very specific to our application development, so I don't know if we'll be able to release it. In the comments of the post below, I also found a link to packtag, which seems to be an open source Java version of this very same functionality.

Via ajaxian:

We love to play with the plumbing don't we. jscsscomp is the latest compressor that uses Nicolas Martin PHP version of the Dean Edwards JavaScript Compressor.

With a swish of mod_rewrite:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*\.)(js|css)$ jscsscomp/jscsscomp.php?q=$1$2 [L,NC]

you can get your JavaScript like this:

HTML:
<script src = "/jscsscomp/yahoo.js, dom.js, event.js, effects/dragdrop.js, slider.js"></script>

drag to resize


Java to JavaScript Compilation with Ajax and Spring Integration

via Ajaxian.

Ben Alex of Interface 21 has written a detailed post on Java to JavaScript compilation.

The article discusses some of the choices out there (GWT, OpenLaszlo) and goes into an open source alternative called Java2Script Pacemaker.

Spring integration is shown and available for download and it concludes:

J2S promises some attractive benefits for projects that require JavaScript compilation or a web browser implementation of SWT. It also interoperates successfully with a Spring backend. J2S' deliberate choice to leverage proven existing technologies such as AST and SWT make it a good example of reusing existing code and developer skills, in turn lowering adoption barriers and the prospect of material API change. If you consider yourself an early adopter, SWT devotee, or need a client-centric, web-based user interface that is built upon the mature SWT UI framework, it is definitely worth taking a closer look at J2S.

Does SWT support do it for you?

Prototype Extension: Dynamic Script Pattern Support

Now, what was I just saying?

via Ajaxian:

Cody Swann was working on a web application that was using the Dynamic Script Pattern, which Dojo has excellent support for, but Prototype didn't.

Cody then extended Prototype to support ScriptSrcTransport similarly to how Dojo does it.

The code below support the Simple, Polling and JSONP and JSON Callbacks described in the Dojo book.

Lazy Loading - Javascript includes on demand

There are several examples of the concept of "lazy loading" out there. Dojo is probably the most well known, but the thing I don't like about Dojo is that the initial include is so expensive (127K!!! - and that's before you include any widgets).

While digging through ajaxpatterns.org I found this entry on On-Demand Javascript that outlines the concept really well, illustrates how one would implement it, and also points to a couple of implementatins already out there (including Dojo). It's worth a quick read, especially as we start considering standardizing some of our code libraries. | Read the rest »

PHP-Based MySQL-to-JSON Converter

via ajaxian

A new PHP component by Adnan Siddiqi accepts a MySQL result set and converts it into a JSON message. MySQL To JSON: | Read the rest »

Reverse Ajax w/ DWR

via ajaxian (of course):

More and more, Ajax apps are using various techniques to keep content fresh in the browser. Essentially, we're talking about reversing the usual communication flow- the server notices something's happened, and wants to tell the browser about it. Server 'calls' browser, not browser calls server.

The popular Java Ajax framework, DWR, recently released milestone 2 towards a 2.0 release, and introduced the term 'Reverse Ajax' in the process, to capture this high-level pattern. This article (via Joe Walker) abstracts the communication details behind a clean API, so you can easily switch between three different implementations of Reverse Ajax: | Read the rest »

Categories

Archives

Links and whatnot