Archive for December, 2005


JSON trumps Ajax for Mashups

Monday, December 19th, 2005

I’ve spent a lot of time over the years playing with different methods of having a web page get data from the server without refreshing the page. One of my major criteria has been to find a method that works across all browsers. A few different methods have cropped up over time, following an evolutionary path.

In 1998, I used Microsoft Remote Scripting, which used a Java applet for its transport layer. Java later became a problem, since it’s blocked by firewalls and no longer automatically supported by all of the main browsers.

In 1999 I started experimenting with frames, then a hidden Iframe, which I used in my JSRS library in 2000. Iframes have become deprecated as of the XHTML specification, and browser history can be affected by their use, making this workable but suboptimal.

In 2000 I wrote RSLite which uses a client-side image object and a cookie. This works across pretty well all browsers but has limited value due to url and cookie length limits.

I started to use and promote Microsoft’s XMLHttp object fairly early on, but its limitation to IE and at that time only beta Mozilla made it not-ready-for-primetime. It has since come into its own in the form of Ajax, however there are still cross-domain scripting limitations, which are an impediment to the kind of Web 2.0 mashups that are some of the most compelling new uses of browser technology.

Danne Lundqvist was amongst the first to talk about the idea of using dynamically-generated script tags to send and receive data. In conjunction with Douglas Crockford‘s JSON JavaScript Object Notation, this method has recently been promoted by Yahoo in their Javascript Developer Center as a way to perform cross-domain data transmission.

Full coverage of the method can be seen on Dan Theurer‘s blog.

I am beginning to think that the combination of JSON and On-Demand-Javascript holds a great deal of promise:

  • Great cross-browser compatibility
  • It is not a hack. Cross-domain script tags are a designed-in browser feature. DOM manipulation is central to modern browsers
  • JSON is a great compact object notation, native to JavaScript yet already implemented in many server-side languages and easy to do for others

It may be just another crayon in the box, but I think it’s going to get a lot of sharpening now that Yahoo is actively promoting JSON.