<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Dev411 Blog: Category prototype</title>
  <subtitle type="html">John Wang on Technology</subtitle>
  <id>tag:www.dev411.com,2005:Typo</id>
  <generator uri="http://www.typosphere.org" version="4.0">Typo</generator>
  <link href="http://www.dev411.com/blog/xml/atom/category/feed.xml" rel="self" type="application/atom+xml"/>
  <link href="http://www.dev411.com/blog/tag/prototype" rel="alternate" type="text/html"/>
  <updated>2007-06-16T12:30:23-05:00</updated>
  <entry>
    <author>
      <name>John Wang</name>
    </author>
    <id>urn:uuid:5e313631b8ed2a057be9cc4d29997c60</id>
    <published>2006-07-28T12:14:00-05:00</published>
    <updated>2007-06-16T12:30:23-05:00</updated>
    <title type="html">Online Dojo JavaScript Compressor</title>
    <link href="http://www.dev411.com/blog/2006/07/28/online-dojo-javascript-compressor" rel="alternate" type="text/html"/>
    <category term="dojo" scheme="http://www.dev411.com/blog/tag/dojo" label="dojo"/>
    <category term="ajax" scheme="http://www.dev411.com/blog/tag/ajax" label="ajax"/>
    <category term="scriptaculous" scheme="http://www.dev411.com/blog/tag/scriptaculous" label="scriptaculous"/>
    <category term="prototype" scheme="http://www.dev411.com/blog/tag/prototype" label="prototype"/>
    <summary type="html">&lt;p&gt;I just put together an &lt;a href="/dojo/javascript_compressor"&gt;online JavaScript Compressor&lt;/a&gt; interface to &lt;a href="http://dojotoolkit.org/docs/compressor_system.html"&gt;Dojo Toolkit's JavaScript Compressor&lt;/a&gt;, &lt;span class="fix"&gt;custom_rhino.jar&lt;/span&gt;. The JavaScript Compressor is used in the final stage of the Dojo Toolkit build process so gets a lot of use. Although there is already an online version, &lt;a href="http://alex.dojotoolkit.org/shrinksafe/"&gt;ShrinkSafe&lt;/a&gt;, I put another version together because:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;It would be nice to have a web app that makes custom Dojo builds people don't have to install the JDK and ant to get a custom Dojo build. This is the primary reason and the compressor is a first step in that direction.&lt;/li&gt;
	&lt;li&gt;There have been &lt;a href="http://www.huddletogether.com/forum/comments.php?DiscussionID=160"&gt;some reports&lt;/a&gt; that the JS produced by ShrinkSafe doesn't work (maybe it's using an outdated &lt;span class="fix"&gt;custom_rhino.jar&lt;/span&gt;?). I want an Dojo-based online system to use myself.&lt;/li&gt;
	&lt;li&gt;It's nice to have more Dojo, Prototype and Scriptaculous integration tests. I used the client code from ShrinkSafe which uses Dojo to add additional file and do Drag-and-Drop along with the Lucid theme which relies on Prototype and Scriptaculous. I learned that &lt;span class="fix"&gt;dojo.js&lt;/span&gt; 0.3.1 needs to be loaded before &lt;span class="fix"&gt;scriptaculous.js&lt;/span&gt; 1.6.1 or Scriptaculous will break Dojo (I updated the &lt;a href="http://www.dev411.com/blog/2006/06/13/dojo-and-prototype-together"&gt;Dojo and Prototype Together&lt;/a&gt; article). My minimal use of the Lucid theme actually doesn't need &lt;span class="fix"&gt;scriptaculous.js&lt;/span&gt; so I can get away with loading just &lt;span class="fix"&gt;dojo.js&lt;/span&gt; 0.3.1, &lt;span class="fix"&gt;prototype.js&lt;/span&gt; 1.5.0 rc0, &lt;span class="fix"&gt;effects.js&lt;/span&gt; (part of Scriptaculous 1.6.1) and &lt;span class="fix"&gt;lucid.js&lt;/span&gt;. &lt;span class="fix"&gt;lucid.js&lt;/span&gt; is part of the Lucid theme.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The JavaScript compressor eats its own dogfood and uses &lt;span class="fix"&gt;prototype.js&lt;/span&gt;, &lt;span class="fix"&gt;effects.js&lt;/span&gt; and &lt;span class="fix"&gt;lucid.js&lt;/span&gt; compressed into a single-line, single file. Here are the compression sizes and ratios for the files. Generally you save about 30%.&lt;/p&gt;

&lt;table id="article_jscompress"&gt;
&lt;tr&gt;
	&lt;th&gt;script&lt;/th&gt;
	&lt;th&gt;uncompressed&lt;/th&gt;
	&lt;th&gt;compressed&lt;br /&gt;multiline&lt;/th&gt;
	&lt;th&gt;ratio&lt;/th&gt;
	&lt;th&gt;compressed&lt;br /&gt;single line&lt;/th&gt;
	&lt;th&gt;ratio&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;prototype.js&lt;/td&gt;
	&lt;td&gt;55,149&lt;/td&gt;
	&lt;td&gt;38,696&lt;/td&gt;
	&lt;td&gt;70%&lt;/td&gt;
	&lt;td&gt;37,154&lt;/td&gt;
	&lt;td&gt;67%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;effects.js&lt;/td&gt;
	&lt;td&gt;32,908&lt;/td&gt;
	&lt;td&gt;23,244&lt;/td&gt;
	&lt;td&gt;71%&lt;/td&gt;
	&lt;td&gt;22,527&lt;/td&gt;
	&lt;td&gt;68%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;lucid.js&lt;/td&gt;
	&lt;td&gt;7,253&lt;/td&gt;
	&lt;td&gt;4,917&lt;/td&gt;
	&lt;td&gt;68%&lt;/td&gt;
	&lt;td&gt;4,741&lt;/td&gt;
	&lt;td&gt;65%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;All files&lt;/td&gt;
	&lt;td&gt;95,310&lt;/td&gt;
	&lt;td&gt;67,570&lt;/td&gt;
	&lt;td&gt;71%&lt;/td&gt;
	&lt;td&gt;65,137&lt;/td&gt;
	&lt;td&gt;68%&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;A number of people are using &lt;a href="http://www.javascriptcompressor.com"&gt;JavaScriptCompressor.com&lt;/a&gt; which is running &lt;a href="http://dean.edwards.name/download/#packer"&gt;Dean Edwards' .NET JavaScript compression code&lt;/a&gt;. This can be used after Dojo's compressor for even more compression.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;I just put together an &lt;a href="/dojo/javascript_compressor"&gt;online JavaScript Compressor&lt;/a&gt; interface to &lt;a href="http://dojotoolkit.org/docs/compressor_system.html"&gt;Dojo Toolkit's JavaScript Compressor&lt;/a&gt;, &lt;span class="fix"&gt;custom_rhino.jar&lt;/span&gt;. The JavaScript Compressor is used in the final stage of the Dojo Toolkit build process so gets a lot of use. Although there is already an online version, &lt;a href="http://alex.dojotoolkit.org/shrinksafe/"&gt;ShrinkSafe&lt;/a&gt;, I put another version together because:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;It would be nice to have a web app that makes custom Dojo builds people don't have to install the JDK and ant to get a custom Dojo build. This is the primary reason and the compressor is a first step in that direction.&lt;/li&gt;
	&lt;li&gt;There have been &lt;a href="http://www.huddletogether.com/forum/comments.php?DiscussionID=160"&gt;some reports&lt;/a&gt; that the JS produced by ShrinkSafe doesn't work (maybe it's using an outdated &lt;span class="fix"&gt;custom_rhino.jar&lt;/span&gt;?). I want an Dojo-based online system to use myself.&lt;/li&gt;
	&lt;li&gt;It's nice to have more Dojo, Prototype and Scriptaculous integration tests. I used the client code from ShrinkSafe which uses Dojo to add additional file and do Drag-and-Drop along with the Lucid theme which relies on Prototype and Scriptaculous. I learned that &lt;span class="fix"&gt;dojo.js&lt;/span&gt; 0.3.1 needs to be loaded before &lt;span class="fix"&gt;scriptaculous.js&lt;/span&gt; 1.6.1 or Scriptaculous will break Dojo (I updated the &lt;a href="http://www.dev411.com/blog/2006/06/13/dojo-and-prototype-together"&gt;Dojo and Prototype Together&lt;/a&gt; article). My minimal use of the Lucid theme actually doesn't need &lt;span class="fix"&gt;scriptaculous.js&lt;/span&gt; so I can get away with loading just &lt;span class="fix"&gt;dojo.js&lt;/span&gt; 0.3.1, &lt;span class="fix"&gt;prototype.js&lt;/span&gt; 1.5.0 rc0, &lt;span class="fix"&gt;effects.js&lt;/span&gt; (part of Scriptaculous 1.6.1) and &lt;span class="fix"&gt;lucid.js&lt;/span&gt;. &lt;span class="fix"&gt;lucid.js&lt;/span&gt; is part of the Lucid theme.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The JavaScript compressor eats its own dogfood and uses &lt;span class="fix"&gt;prototype.js&lt;/span&gt;, &lt;span class="fix"&gt;effects.js&lt;/span&gt; and &lt;span class="fix"&gt;lucid.js&lt;/span&gt; compressed into a single-line, single file. Here are the compression sizes and ratios for the files. Generally you save about 30%.&lt;/p&gt;

&lt;table id="article_jscompress"&gt;
&lt;tr&gt;
	&lt;th&gt;script&lt;/th&gt;
	&lt;th&gt;uncompressed&lt;/th&gt;
	&lt;th&gt;compressed&lt;br /&gt;multiline&lt;/th&gt;
	&lt;th&gt;ratio&lt;/th&gt;
	&lt;th&gt;compressed&lt;br /&gt;single line&lt;/th&gt;
	&lt;th&gt;ratio&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;prototype.js&lt;/td&gt;
	&lt;td&gt;55,149&lt;/td&gt;
	&lt;td&gt;38,696&lt;/td&gt;
	&lt;td&gt;70%&lt;/td&gt;
	&lt;td&gt;37,154&lt;/td&gt;
	&lt;td&gt;67%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;effects.js&lt;/td&gt;
	&lt;td&gt;32,908&lt;/td&gt;
	&lt;td&gt;23,244&lt;/td&gt;
	&lt;td&gt;71%&lt;/td&gt;
	&lt;td&gt;22,527&lt;/td&gt;
	&lt;td&gt;68%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;lucid.js&lt;/td&gt;
	&lt;td&gt;7,253&lt;/td&gt;
	&lt;td&gt;4,917&lt;/td&gt;
	&lt;td&gt;68%&lt;/td&gt;
	&lt;td&gt;4,741&lt;/td&gt;
	&lt;td&gt;65%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;All files&lt;/td&gt;
	&lt;td&gt;95,310&lt;/td&gt;
	&lt;td&gt;67,570&lt;/td&gt;
	&lt;td&gt;71%&lt;/td&gt;
	&lt;td&gt;65,137&lt;/td&gt;
	&lt;td&gt;68%&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;A number of people are using &lt;a href="http://www.javascriptcompressor.com"&gt;JavaScriptCompressor.com&lt;/a&gt; which is running &lt;a href="http://dean.edwards.name/download/#packer"&gt;Dean Edwards' .NET JavaScript compression code&lt;/a&gt;. This can be used after Dojo's compressor for even more compression.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <author>
      <name>John Wang</name>
    </author>
    <id>urn:uuid:4affdc8fb3cb2fc9e8b14d8a6252ebe3</id>
    <published>2006-07-20T17:22:00-05:00</published>
    <updated>2007-06-16T12:30:23-05:00</updated>
    <title type="html">Prototype's future in Rails</title>
    <link href="http://www.dev411.com/blog/2006/07/20/prototypes-future-in-rails" rel="alternate" type="text/html"/>
    <category term="rails" scheme="http://www.dev411.com/blog/tag/rails" label="rails"/>
    <category term="ajax" scheme="http://www.dev411.com/blog/tag/ajax" label="ajax"/>
    <category term="scriptaculous" scheme="http://www.dev411.com/blog/tag/scriptaculous" label="scriptaculous"/>
    <category term="prototype" scheme="http://www.dev411.com/blog/tag/prototype" label="prototype"/>
    <summary type="html">&lt;p&gt;The future of Prototype (the JavaScript AJAX library), both as a stand-alone library and as a part of Rails, is being discussed by the community on the &lt;span class="fix"&gt;rails-spinoffs&lt;/span&gt; list. The primary concerns appear to be:&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;The future of Prototype (the JavaScript AJAX library), both as a stand-alone library and as a part of Rails, is being discussed by the community on the &lt;span class="fix"&gt;rails-spinoffs&lt;/span&gt; list. The primary concerns appear to be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prototype is driven by one person who hasn't been very active on the list. Some patches are integrated but often without communication&lt;/li&gt;
&lt;li&gt;it is difficult for others to contribute&lt;/li&gt;
&lt;li&gt;there is no visibility into the roadmap for prototype&lt;/li&gt;
&lt;li&gt;prototype is "falling behind" relative to other libraries&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The one person vs. community aspect of the discussion reminds me of Red Hat rebuilds. When Red Hat stopped distributing free binaries, a number of projects took advantage of GPL and started providing free rebuild binaries. At first, &lt;a href="http://www.whiteboxlinux.org/"&gt;White Box Enterprise Linux (WBEL)&lt;/a&gt; was the most popular and wide-spread rebuild but it was maintained by one person who occasionally got busy. It was eventually overtaken by &lt;a href="http://www.centos.org"&gt;CentOS&lt;/a&gt; which is maintained by a community.&lt;/p&gt;

&lt;p&gt;For now, Prototype will remain popular because it comes bundled with Rails and is the basis for RJS and Scriptaculous. Thomas Fuchs has come out and said, "script.aculo.us will always depend on Prototype". Still, I wonder if community maintenance isn't a better way to go for something that's relied on by so many people. Some are even concerned that Rails itself will become less viable if it continues to attach itself to Prototype and the project management doesn't change.&lt;/p&gt;

&lt;p&gt;You can follow the thread by going to the list &lt;a href="http://wrath.rubyonrails.org/pipermail/rails-spinoffs/2006-July/thread.html"&gt;archives page&lt;/a&gt; and looking for the subject name "Documenting Prototype...". &lt;a href="http://wrath.rubyonrails.org/pipermail/rails-spinoffs/2006-July/005139.html"&gt;Greg Hill's post&lt;/a&gt; seems like a reasonable place to start.&lt;/p&gt;</content>
  </entry>
  <entry>
    <author>
      <name>John Wang</name>
    </author>
    <id>urn:uuid:fce7d6761254476fab563de4285e7fd6</id>
    <published>2006-06-30T12:49:00-05:00</published>
    <updated>2007-06-16T12:30:22-05:00</updated>
    <title type="html">Should there be a standard X-Ajax-Engine request header?</title>
    <link href="http://www.dev411.com/blog/2006/06/30/should-there-be-a-xmlhttprequest-user-agent" rel="alternate" type="text/html"/>
    <category term="mochikit" scheme="http://www.dev411.com/blog/tag/mochikit" label="mochikit"/>
    <category term="dojo" scheme="http://www.dev411.com/blog/tag/dojo" label="dojo"/>
    <category term="ajax" scheme="http://www.dev411.com/blog/tag/ajax" label="ajax"/>
    <category term="prototype" scheme="http://www.dev411.com/blog/tag/prototype" label="prototype"/>
    <summary type="html">&lt;p&gt;A little while ago &lt;a href="/blog/2006/05/31/prototype-json-and-catalyst"&gt;I was looking at JSON and Catalyst::View::JSON&lt;/a&gt; (a server-side library to provide some JSON repsonse magic for &lt;a href="http://www.catalystframework.org"&gt;Catalyst&lt;/a&gt;) and I discovered that AJAX libraries auto-eval JSON differently, Dojo looks in the response body and Prototype looks in the X-JSON header (read about &lt;a href="/blog/2006/06/01/prototype-x-json-fails-on-long-value-in-ie"&gt;X-JSON problems with IE 6&lt;/a&gt;). This got me thinking that there's no standard way for the server to tell what kind of AJAX library is making the request. Prototype sets the &lt;span class="fix"&gt;X-Requested-With&lt;/span&gt; and &lt;span class="fix"&gt;X-Prototype-Version&lt;/span&gt; as:&lt;/p&gt;

&lt;pre&gt;var requestHeaders =
  ['X-Requested-With', XMLHttpRequest',
   'X-Prototype-Version', Prototype.Version,&lt;/pre&gt;

&lt;p&gt;For Dojo, some people are manually sending a request header along the lines of &lt;span class="fix"&gt;isDojo:true&lt;/span&gt;. MochiKit doesn't currently send an identifier.&lt;/p&gt;

&lt;p&gt;I tend to prefer a bit more information such as the library version. Does it make sense for AJAX libraries to send a standard User-Agent along the lines of &lt;span class="fix"&gt;X-XMLHttpRequest-User-Agent&lt;/span&gt; (&lt;span class="fix"&gt;X-AJAX-User-Agent&lt;/span&gt; is shorter but may not be as correct; subsequent to the initial post, a discussion with Alex Russell generated the &lt;span class="fix"&gt;X-Ajax-Engine&lt;/span&gt; name which has been incorporated below). Something shorter is preferable but this is just an initial proposal. It would also remove the need for Prototype's separate &lt;span class="fix"&gt;X-Requested-With&lt;/span&gt; header since having &lt;span class="fix"&gt;X-Ajax-Engine&lt;/span&gt; set at all would indicate &lt;span class="fix"&gt;XMLHttpRequest&lt;/span&gt;. The format could follow the one established for &lt;a href="http://en.wikipedia.org/wiki/User_agent"&gt;User-Agent&lt;/a&gt;:&lt;/p&gt;

&lt;pre&gt;X-Ajax-Engine: &amp;lt;library_name&amp;gt;/&amp;lt;library_version&amp;gt;&lt;/pre&gt;

&lt;p&gt;This can be done manually with Dojo, MochiKit and Prototype as follows:&lt;/p&gt;

&lt;pre&gt;// in a Dojo.io.bind call:
headers: {
 'X-Ajax-Engine':'Dojo/'+dojo.version
}&lt;/pre&gt;

&lt;pre&gt;// for MochiKit:
req.setRequestHeader(
  'X-Ajax-Engine',
  'MochiKit/'+MochiKit.Async.VERSION
)&lt;/pre&gt;

&lt;pre&gt;// in a Prototype AJAX.Request call:
requestHeaders: [
  'X-Ajax-Engine',
  'Prototype/'+Prototype.Version
]&lt;/pre&gt;

&lt;p&gt;Optional information could be added in parenthesis afterwards, e.g. Dojo Toolkit could include the edition name or something along the lines of "Custom Build" like (I'm not sure if other libraries have a reason to do this):&lt;/p&gt;

&lt;pre&gt;X-Ajax-Engine: Dojo/0.3.1 (BrowserIO)&lt;/pre&gt;

&lt;p&gt;If client libraries started using this or something similar, server-side identification could start (attempting to) depend on something that was standardized. Standardization can even be proposed as an addition to the &lt;a href="http://www.w3.org/TR/XMLHttpRequest/"&gt;W3C's XMLHttpRequest efforts&lt;/a&gt;. I think standardization would be great because it will probably happen eventually and for now it would make server-side identification more reliable.&lt;/p&gt;

&lt;p&gt;UPDATE 1: Less than a week after I posted this, a related issue came up on the &lt;a href="http://groups.google.com/group/mochikit/browse_thread/thread/9f88a002d7a2be5f/c340d191d18a89bf"&gt;MochiKit Google Group&lt;/a&gt; involving adding a &lt;span class="fix"&gt;X-MochiKit-Version&lt;/span&gt; header to mimic &lt;span class="fix"&gt;X-Prototype-Version&lt;/span&gt;. I put in a word for standardization and after discussing this with Alex Russell (see below) posted back to the group. Seems like we may get a defacto standardization on &lt;span class="fix"&gt;X-Ajax-Engine&lt;/span&gt; which would be nice.&lt;/p&gt;

&lt;p&gt;UPDATE 2: I spoke to Alex Russell of Dojo Toolkit about this and he thought this is a good idea. Apparently if you set &lt;span class="fix"&gt;sendTransport&lt;/span&gt; in dojo.io.bind, an identifier (but not version number) will get sent, however it seems not many people know about this. We discussed shorter names and Alex came up with &lt;span class="fix"&gt;X-Ajax-Engine&lt;/span&gt;. He mentioned he could bring this up at the &lt;a href="http://www.openajaxalliance.org/"&gt;OpenAjax Alliance&lt;/a&gt;.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;A little while ago &lt;a href="/blog/2006/05/31/prototype-json-and-catalyst"&gt;I was looking at JSON and Catalyst::View::JSON&lt;/a&gt; (a server-side library to provide some JSON repsonse magic for &lt;a href="http://www.catalystframework.org"&gt;Catalyst&lt;/a&gt;) and I discovered that AJAX libraries auto-eval JSON differently, Dojo looks in the response body and Prototype looks in the X-JSON header (read about &lt;a href="/blog/2006/06/01/prototype-x-json-fails-on-long-value-in-ie"&gt;X-JSON problems with IE 6&lt;/a&gt;). This got me thinking that there's no standard way for the server to tell what kind of AJAX library is making the request. Prototype sets the &lt;span class="fix"&gt;X-Requested-With&lt;/span&gt; and &lt;span class="fix"&gt;X-Prototype-Version&lt;/span&gt; as:&lt;/p&gt;

&lt;pre&gt;var requestHeaders =
  ['X-Requested-With', XMLHttpRequest',
   'X-Prototype-Version', Prototype.Version,&lt;/pre&gt;

&lt;p&gt;For Dojo, some people are manually sending a request header along the lines of &lt;span class="fix"&gt;isDojo:true&lt;/span&gt;. MochiKit doesn't currently send an identifier.&lt;/p&gt;

&lt;p&gt;I tend to prefer a bit more information such as the library version. Does it make sense for AJAX libraries to send a standard User-Agent along the lines of &lt;span class="fix"&gt;X-XMLHttpRequest-User-Agent&lt;/span&gt; (&lt;span class="fix"&gt;X-AJAX-User-Agent&lt;/span&gt; is shorter but may not be as correct; subsequent to the initial post, a discussion with Alex Russell generated the &lt;span class="fix"&gt;X-Ajax-Engine&lt;/span&gt; name which has been incorporated below). Something shorter is preferable but this is just an initial proposal. It would also remove the need for Prototype's separate &lt;span class="fix"&gt;X-Requested-With&lt;/span&gt; header since having &lt;span class="fix"&gt;X-Ajax-Engine&lt;/span&gt; set at all would indicate &lt;span class="fix"&gt;XMLHttpRequest&lt;/span&gt;. The format could follow the one established for &lt;a href="http://en.wikipedia.org/wiki/User_agent"&gt;User-Agent&lt;/a&gt;:&lt;/p&gt;

&lt;pre&gt;X-Ajax-Engine: &amp;lt;library_name&amp;gt;/&amp;lt;library_version&amp;gt;&lt;/pre&gt;

&lt;p&gt;This can be done manually with Dojo, MochiKit and Prototype as follows:&lt;/p&gt;

&lt;pre&gt;// in a Dojo.io.bind call:
headers: {
 'X-Ajax-Engine':'Dojo/'+dojo.version
}&lt;/pre&gt;

&lt;pre&gt;// for MochiKit:
req.setRequestHeader(
  'X-Ajax-Engine',
  'MochiKit/'+MochiKit.Async.VERSION
)&lt;/pre&gt;

&lt;pre&gt;// in a Prototype AJAX.Request call:
requestHeaders: [
  'X-Ajax-Engine',
  'Prototype/'+Prototype.Version
]&lt;/pre&gt;

&lt;p&gt;Optional information could be added in parenthesis afterwards, e.g. Dojo Toolkit could include the edition name or something along the lines of "Custom Build" like (I'm not sure if other libraries have a reason to do this):&lt;/p&gt;

&lt;pre&gt;X-Ajax-Engine: Dojo/0.3.1 (BrowserIO)&lt;/pre&gt;

&lt;p&gt;If client libraries started using this or something similar, server-side identification could start (attempting to) depend on something that was standardized. Standardization can even be proposed as an addition to the &lt;a href="http://www.w3.org/TR/XMLHttpRequest/"&gt;W3C's XMLHttpRequest efforts&lt;/a&gt;. I think standardization would be great because it will probably happen eventually and for now it would make server-side identification more reliable.&lt;/p&gt;

&lt;p&gt;UPDATE 1: Less than a week after I posted this, a related issue came up on the &lt;a href="http://groups.google.com/group/mochikit/browse_thread/thread/9f88a002d7a2be5f/c340d191d18a89bf"&gt;MochiKit Google Group&lt;/a&gt; involving adding a &lt;span class="fix"&gt;X-MochiKit-Version&lt;/span&gt; header to mimic &lt;span class="fix"&gt;X-Prototype-Version&lt;/span&gt;. I put in a word for standardization and after discussing this with Alex Russell (see below) posted back to the group. Seems like we may get a defacto standardization on &lt;span class="fix"&gt;X-Ajax-Engine&lt;/span&gt; which would be nice.&lt;/p&gt;

&lt;p&gt;UPDATE 2: I spoke to Alex Russell of Dojo Toolkit about this and he thought this is a good idea. Apparently if you set &lt;span class="fix"&gt;sendTransport&lt;/span&gt; in dojo.io.bind, an identifier (but not version number) will get sent, however it seems not many people know about this. We discussed shorter names and Alex came up with &lt;span class="fix"&gt;X-Ajax-Engine&lt;/span&gt;. He mentioned he could bring this up at the &lt;a href="http://www.openajaxalliance.org/"&gt;OpenAjax Alliance&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <author>
      <name>John Wang</name>
    </author>
    <id>urn:uuid:38c104ddc9167cbf60448098739c9316</id>
    <published>2006-06-13T21:31:00-05:00</published>
    <updated>2007-06-16T12:30:22-05:00</updated>
    <title type="html">Dojo and Prototype Together</title>
    <link href="http://www.dev411.com/blog/2006/06/13/dojo-and-prototype-together" rel="alternate" type="text/html"/>
    <category term="dojo" scheme="http://www.dev411.com/blog/tag/dojo" label="dojo"/>
    <category term="autocomplete" scheme="http://www.dev411.com/blog/tag/autocomplete" label="autocomplete"/>
    <category term="ajax" scheme="http://www.dev411.com/blog/tag/ajax" label="ajax"/>
    <category term="scriptaculous" scheme="http://www.dev411.com/blog/tag/scriptaculous" label="scriptaculous"/>
    <category term="prototype" scheme="http://www.dev411.com/blog/tag/prototype" label="prototype"/>
    <summary type="html">&lt;p&gt;I just wanted to report and let everyone know with &lt;a href="http://prototype.conio.net"&gt;Prototype&lt;/a&gt; 1.5.x, &lt;a href="http://www.dojotoolkit.org"&gt;Dojo Toolkit&lt;/a&gt; and Prototype should now be interoperable. Earlier versions of prototype.js extended the JavaScript Object prototype that would break third-party JavaScript but this is no longer being done. A few people, including myself, have been using them together without any problems. The prototype website still offers 1.4.0 as the current version, however 1.5.0 rc0 is included with &lt;a href="http://script.aculo.us"&gt;Scriptaculous&lt;/a&gt; 1.6.1. I'm currently using prototype 1.5.0 rc0 with Dojo 0.3.1 and Scriptaculous 1.5 rc4. Although Scriptaculous 1.6.1 is available, it breaks autocomplete for me and I haven't had time to track down what changed yet. Hopefully soon.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; The Scriptaculous 1.6.1 issue has been reported to RoR as &lt;a href="http://dev.rubyonrails.org/ticket/5673"&gt;ticket #5673&lt;/a&gt;. This has since been fixed with Scriptaculous 1.6.2. I'm now using Dojo 0.3.1, Prototype 1.5.0 rc0 and Scriptaculous 1.6.2.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPDATE 2:&lt;/strong&gt; When running &lt;span class="fix"&gt;dojo.js&lt;/span&gt; and &lt;span class="fix"&gt;scriptaculous.js&lt;/span&gt; together, make sure you load &lt;span class="fix"&gt;dojo.js&lt;/span&gt; first. Loading &lt;span class="fix"&gt;scriptaculous.js&lt;/span&gt; first will cause Dojo to fail.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;I just wanted to report and let everyone know with &lt;a href="http://prototype.conio.net"&gt;Prototype&lt;/a&gt; 1.5.x, &lt;a href="http://www.dojotoolkit.org"&gt;Dojo Toolkit&lt;/a&gt; and Prototype should now be interoperable. Earlier versions of prototype.js extended the JavaScript Object prototype that would break third-party JavaScript but this is no longer being done. A few people, including myself, have been using them together without any problems. The prototype website still offers 1.4.0 as the current version, however 1.5.0 rc0 is included with &lt;a href="http://script.aculo.us"&gt;Scriptaculous&lt;/a&gt; 1.6.1. I'm currently using prototype 1.5.0 rc0 with Dojo 0.3.1 and Scriptaculous 1.5 rc4. Although Scriptaculous 1.6.1 is available, it breaks autocomplete for me and I haven't had time to track down what changed yet. Hopefully soon.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; The Scriptaculous 1.6.1 issue has been reported to RoR as &lt;a href="http://dev.rubyonrails.org/ticket/5673"&gt;ticket #5673&lt;/a&gt;. This has since been fixed with Scriptaculous 1.6.2. I'm now using Dojo 0.3.1, Prototype 1.5.0 rc0 and Scriptaculous 1.6.2.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPDATE 2:&lt;/strong&gt; When running &lt;span class="fix"&gt;dojo.js&lt;/span&gt; and &lt;span class="fix"&gt;scriptaculous.js&lt;/span&gt; together, make sure you load &lt;span class="fix"&gt;dojo.js&lt;/span&gt; first. Loading &lt;span class="fix"&gt;scriptaculous.js&lt;/span&gt; first will cause Dojo to fail.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <author>
      <name>John Wang</name>
    </author>
    <id>urn:uuid:77762545b1dda44d93f114f89f64dfb0</id>
    <published>2006-06-05T20:52:00-05:00</published>
    <updated>2007-06-16T12:30:22-05:00</updated>
    <title type="html">HTML::Prototype - AJAX Without JavaScript</title>
    <link href="http://www.dev411.com/blog/2006/06/05/html-prototype-ajax-without-javascript" rel="alternate" type="text/html"/>
    <category term="catalyst" scheme="http://www.dev411.com/blog/tag/catalyst" label="catalyst"/>
    <category term="perl" scheme="http://www.dev411.com/blog/tag/perl" label="perl"/>
    <category term="templatetoolkit" scheme="http://www.dev411.com/blog/tag/templatetoolkit" label="templatetoolkit"/>
    <category term="ajax" scheme="http://www.dev411.com/blog/tag/ajax" label="ajax"/>
    <category term="scriptaculous" scheme="http://www.dev411.com/blog/tag/scriptaculous" label="scriptaculous"/>
    <category term="prototype" scheme="http://www.dev411.com/blog/tag/prototype" label="prototype"/>
    <summary type="html">&lt;p&gt;&lt;a href="http://search.cpan.org/~esskar/HTML-Prototype-1.45/lib/HTML/Prototype.pm"&gt;HTML::Prototype&lt;/a&gt; is by far the most painless way to get started with AJAX that I've found. Simply put, you do not need to know or write any JavaScript! HTML::Prototype is a Perl module on CPAN that wraps the prototype AJAX library and Script.aculo.us effects library with Perl helper methods so you don't need to write a single line of JavaScript to get some great effects. There are also a number of modules that wrap HTML::Prototype for integration with &lt;a href="http://search.cpan.org/~sri/Catalyst-Plugin-Prototype-1.32/lib/Catalyst/Plugin/Prototype.pm"&gt;Catalyst&lt;/a&gt;, &lt;a href="http://search.cpan.org/~ceeshek/CGI-Application-Plugin-HTMLPrototype-0.20/lib/CGI/Application/Plugin/HTMLPrototype.pm"&gt;CGI::Application&lt;/a&gt;, &lt;a href="http://search.cpan.org/~bauerb/Template-Plugin-HTML-Prototype-0.01/lib/Template/Plugin/HTML/Prototype.pm"&gt;Template Toolkit&lt;/a&gt; and others.&lt;/p&gt;

&lt;p&gt;There are a number of convenient methods such as &lt;span class="fix"&gt;link_to_remote()&lt;/span&gt; and &lt;span class="fix"&gt;submit_to_remote()&lt;/span&gt; that create a link and form button to make an AJAX call and populate the innerHTML of a specified DOM element with the response body. Syntactic sugar to be sure as the JS generated by HTML::Prototype is very simple once you look at it, but the beauty is that you never have to.&lt;/p&gt;

&lt;p&gt;To truly appreciate HTML::Prototype you need to use some of Scriptaculous' more advanced widgets such as autocomplete. Sebastian Riedel put together a screencast using Catalyst that demonstrates how easy it is to use. Links to the screencast are available on the Catalyst wiki movies page:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://dev.catalyst.perl.org/wiki/Movies"&gt;http://dev.catalyst.perl.org/wiki/Movies&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another great thing about having HTML::Prototype generate the JS syntax for you is that you can learn prototype syntax just by View Source. I picked up enough of prototype's JS syntax this way that I haven't looked at the docs yet.&lt;/p&gt;

&lt;p&gt;I've recently removed HTML::Prototype from a project in favor of using &lt;span class="fix"&gt;prototype.js&lt;/span&gt; and &lt;span class="fix"&gt;scriptaculous.js&lt;/span&gt; directly and I'm evaluating the Dojo Toolkit but HTML::Prototype let me get started with very effective, painless AJAX functionality. I used it with Catalyst::Plugin::Prototype and thought 'this is how frameworks make you productive.' Thanks to all the contributors.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;&lt;a href="http://search.cpan.org/~esskar/HTML-Prototype-1.45/lib/HTML/Prototype.pm"&gt;HTML::Prototype&lt;/a&gt; is by far the most painless way to get started with AJAX that I've found. Simply put, you do not need to know or write any JavaScript! HTML::Prototype is a Perl module on CPAN that wraps the prototype AJAX library and Script.aculo.us effects library with Perl helper methods so you don't need to write a single line of JavaScript to get some great effects. There are also a number of modules that wrap HTML::Prototype for integration with &lt;a href="http://search.cpan.org/~sri/Catalyst-Plugin-Prototype-1.32/lib/Catalyst/Plugin/Prototype.pm"&gt;Catalyst&lt;/a&gt;, &lt;a href="http://search.cpan.org/~ceeshek/CGI-Application-Plugin-HTMLPrototype-0.20/lib/CGI/Application/Plugin/HTMLPrototype.pm"&gt;CGI::Application&lt;/a&gt;, &lt;a href="http://search.cpan.org/~bauerb/Template-Plugin-HTML-Prototype-0.01/lib/Template/Plugin/HTML/Prototype.pm"&gt;Template Toolkit&lt;/a&gt; and others.&lt;/p&gt;

&lt;p&gt;There are a number of convenient methods such as &lt;span class="fix"&gt;link_to_remote()&lt;/span&gt; and &lt;span class="fix"&gt;submit_to_remote()&lt;/span&gt; that create a link and form button to make an AJAX call and populate the innerHTML of a specified DOM element with the response body. Syntactic sugar to be sure as the JS generated by HTML::Prototype is very simple once you look at it, but the beauty is that you never have to.&lt;/p&gt;

&lt;p&gt;To truly appreciate HTML::Prototype you need to use some of Scriptaculous' more advanced widgets such as autocomplete. Sebastian Riedel put together a screencast using Catalyst that demonstrates how easy it is to use. Links to the screencast are available on the Catalyst wiki movies page:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://dev.catalyst.perl.org/wiki/Movies"&gt;http://dev.catalyst.perl.org/wiki/Movies&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another great thing about having HTML::Prototype generate the JS syntax for you is that you can learn prototype syntax just by View Source. I picked up enough of prototype's JS syntax this way that I haven't looked at the docs yet.&lt;/p&gt;

&lt;p&gt;I've recently removed HTML::Prototype from a project in favor of using &lt;span class="fix"&gt;prototype.js&lt;/span&gt; and &lt;span class="fix"&gt;scriptaculous.js&lt;/span&gt; directly and I'm evaluating the Dojo Toolkit but HTML::Prototype let me get started with very effective, painless AJAX functionality. I used it with Catalyst::Plugin::Prototype and thought 'this is how frameworks make you productive.' Thanks to all the contributors.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <author>
      <name>John Wang</name>
    </author>
    <id>urn:uuid:5bd12f134d64f49b67f22215e9476f5f</id>
    <published>2006-06-01T15:14:00-05:00</published>
    <updated>2007-06-16T12:30:22-05:00</updated>
    <title type="html">Prototype - X-JSON fails on long value in IE</title>
    <link href="http://www.dev411.com/blog/2006/06/01/prototype-x-json-fails-on-long-value-in-ie" rel="alternate" type="text/html"/>
    <category term="json" scheme="http://www.dev411.com/blog/tag/json" label="json"/>
    <category term="ie" scheme="http://www.dev411.com/blog/tag/ie" label="ie"/>
    <category term="ajax" scheme="http://www.dev411.com/blog/tag/ajax" label="ajax"/>
    <category term="prototype" scheme="http://www.dev411.com/blog/tag/prototype" label="prototype"/>
    <summary type="html">&lt;p&gt;Unlike Dojo Toolkit and other client-side AJAX libraries that read a JSON object from the response body, prototype.js reads it from the custom X-JSON header. I didn't run into any problems with prototype's approach developing on Firefox but I soon discovered IE 6 has a max header size that will cause prototype 1.5.0 rc0's evalJSON method to silently fail with an unreported [object Error] error. In my case, IE 6 would handle an X-JSON string with length of 138 bytes but would fail with a length of 1659 bytes. Firefox 1.5.0.3 and 1.0.7 worked fine with both strings. I'm not sure what IE 6's exact limit is but the fact there's a limit at all is discouraging IMO.&lt;/p&gt;

&lt;p&gt;The argument I've seen for putting the JSON object in X-JSON is that you can put a separate large quanity of HTML in the response body. This design works well when you only have one or zero large quantities of HTML. As soon as you have two, you need to either put them both in the response body using another serialized data notation or put them both in the JSON object and put the JSON object in the response body instead of the X-JSON header. It seems better to simply expect the JSON object in the response body in all cases than in cases when there's only one or zero large return values.&lt;/p&gt;

&lt;p&gt;Let's take a look at an example. In the following the one Ajax JSON response can return meta data about the overall response ("Result":"ok") as well as a list of "Posts", say when updating a post list on something like Digg's homepage. Further more a list of "Hot Stories" can simultaneously updated in the same request. Each one of the stories may have a description or overall information that exceeds IE 6's max header length.&lt;/p&gt;

&lt;pre&gt;{
  "Result":"ok",
  "Posts":[
    {
      "time":1149349580,
      "id":100001,
      "title":"Article 11 title",
      "desc":"Article 11 desc
         (longer than IE header length)",
      "votes":120,
      "comments":5,
      "submitter":"garfield"
    },
    {
      "time":1149349583,
      "id":100002,
      "title":"Article 12 title",
      "desc":"Article 12 desc
         (longer than IE header length)",
      "votes":125,
      "comments":15,
      "submitter":"garfield"
    }
  ],
  "Hot Stories":[
    {
      "time":1149348000,
      "id":1001,
      "title":"Hot Article 1 title",
      "desc":"Hot Article 1 desc
         (longer than IE header length)",
      "votes":1120,
      "comments":115,
      "submitter":"garfield"
    },
    {
      "time":1149349000,
      "id":1002,
      "title":"Hot Article 2 title",
      "desc":"Hot Article 1 desc
         (longer than IE header length)",
      "votes":1120,
      "comments":115,
      "submitter":"garfield"
    }
  ]
}&lt;/pre&gt;

&lt;p&gt;I understand where having a proprietary X-JSON header and a separate response body is useful however I view those situations as a subset of a more generic, and powerful, use. With more complex return values, putting the JSON object in the response body is ultimately a more flexible and extensible design.&lt;/p&gt;

&lt;p&gt;I'll continue to use prototype for now but I'm going to set all my JSON objects in the response body and eval it myself given IE 6's short comings. A bigger concern for me is that I feel Prototype's use of putting the JSON object in X-JSON will encourage inefficient AJAX implementations that end up using more HTTP request/response cycles than necessary. I really hope prototype.js will move their auto-eval feature to operate on the response body due to this problem and to make it more compatible with other JS AJAX libraries at the same time.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;Unlike Dojo Toolkit and other client-side AJAX libraries that read a JSON object from the response body, prototype.js reads it from the custom X-JSON header. I didn't run into any problems with prototype's approach developing on Firefox but I soon discovered IE 6 has a max header size that will cause prototype 1.5.0 rc0's evalJSON method to silently fail with an unreported [object Error] error. In my case, IE 6 would handle an X-JSON string with length of 138 bytes but would fail with a length of 1659 bytes. Firefox 1.5.0.3 and 1.0.7 worked fine with both strings. I'm not sure what IE 6's exact limit is but the fact there's a limit at all is discouraging IMO.&lt;/p&gt;

&lt;p&gt;The argument I've seen for putting the JSON object in X-JSON is that you can put a separate large quanity of HTML in the response body. This design works well when you only have one or zero large quantities of HTML. As soon as you have two, you need to either put them both in the response body using another serialized data notation or put them both in the JSON object and put the JSON object in the response body instead of the X-JSON header. It seems better to simply expect the JSON object in the response body in all cases than in cases when there's only one or zero large return values.&lt;/p&gt;

&lt;p&gt;Let's take a look at an example. In the following the one Ajax JSON response can return meta data about the overall response ("Result":"ok") as well as a list of "Posts", say when updating a post list on something like Digg's homepage. Further more a list of "Hot Stories" can simultaneously updated in the same request. Each one of the stories may have a description or overall information that exceeds IE 6's max header length.&lt;/p&gt;

&lt;pre&gt;{
  "Result":"ok",
  "Posts":[
    {
      "time":1149349580,
      "id":100001,
      "title":"Article 11 title",
      "desc":"Article 11 desc
         (longer than IE header length)",
      "votes":120,
      "comments":5,
      "submitter":"garfield"
    },
    {
      "time":1149349583,
      "id":100002,
      "title":"Article 12 title",
      "desc":"Article 12 desc
         (longer than IE header length)",
      "votes":125,
      "comments":15,
      "submitter":"garfield"
    }
  ],
  "Hot Stories":[
    {
      "time":1149348000,
      "id":1001,
      "title":"Hot Article 1 title",
      "desc":"Hot Article 1 desc
         (longer than IE header length)",
      "votes":1120,
      "comments":115,
      "submitter":"garfield"
    },
    {
      "time":1149349000,
      "id":1002,
      "title":"Hot Article 2 title",
      "desc":"Hot Article 1 desc
         (longer than IE header length)",
      "votes":1120,
      "comments":115,
      "submitter":"garfield"
    }
  ]
}&lt;/pre&gt;

&lt;p&gt;I understand where having a proprietary X-JSON header and a separate response body is useful however I view those situations as a subset of a more generic, and powerful, use. With more complex return values, putting the JSON object in the response body is ultimately a more flexible and extensible design.&lt;/p&gt;

&lt;p&gt;I'll continue to use prototype for now but I'm going to set all my JSON objects in the response body and eval it myself given IE 6's short comings. A bigger concern for me is that I feel Prototype's use of putting the JSON object in X-JSON will encourage inefficient AJAX implementations that end up using more HTTP request/response cycles than necessary. I really hope prototype.js will move their auto-eval feature to operate on the response body due to this problem and to make it more compatible with other JS AJAX libraries at the same time.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <author>
      <name>John Wang</name>
    </author>
    <id>urn:uuid:f9fb9eb8e9b9f0de3b18a6f89c2f0b45</id>
    <published>2006-05-31T19:42:00-05:00</published>
    <updated>2007-06-16T12:30:22-05:00</updated>
    <title type="html">Prototype, JSON and Catalyst</title>
    <link href="http://www.dev411.com/blog/2006/05/31/prototype-json-and-catalyst" rel="alternate" type="text/html"/>
    <category term="json" scheme="http://www.dev411.com/blog/tag/json" label="json"/>
    <category term="catalyst" scheme="http://www.dev411.com/blog/tag/catalyst" label="catalyst"/>
    <category term="perl" scheme="http://www.dev411.com/blog/tag/perl" label="perl"/>
    <category term="ajax" scheme="http://www.dev411.com/blog/tag/ajax" label="ajax"/>
    <category term="prototype" scheme="http://www.dev411.com/blog/tag/prototype" label="prototype"/>
    <summary type="html">&lt;p&gt;I use the prototype.js library (aka prototype) for AJAX and recently moved to using JSON to return multiple elements instead of a single one. I had to rearchitect my client request code and my server code to handle JSON but it's worth it to minimize the number of HTTP requests. I use Catalyst and JSON::Syck which make generating the JSON response on the server-side very easy.&lt;/p&gt;

&lt;p&gt;Prototype.js is interesting in that it auto-evals a JSON object that's placed in the X-JSON header instead of the response body like other libaries such as Dojo Toolkit. This allows you to send HTML in the response body but I'm not convinced this is a good implementation since it supports only one HTML fragment in the response body. I think it would be better to simply put the JSON object in the response body and have all the HTML fragments in the JSON object. I just seems cleaner to put all the HTML fragments in JSON instead of fragment 1 in the response body and fragments 2-n in JSON. Although I have the X-JSON header working, I may just move to the more standard JSON in response body approach and eval the JSON string myself. To read the auto-evaled JSON response, the following example expects a JSON associative array and displays the value of the myItem key (more code is available in the wiki link below):&lt;/p&gt;

&lt;pre&gt;onComplete: function( request, json ) {
    alert( json.myItem );
}&lt;/pre&gt;

&lt;p&gt;On the server-side, I use the Catalyst framework to set the header and JSON::Syck to transform Perl data structures to JSON. JSON::Syck is a wrapper around the C libsyck library and very fast. There is a view, Catalyst::View::JSON, however it puts the JSON string in the response body because that is what Dojo and other libraries expect. Since AJAX libraries don't idnetify themselves in anyway to the server (e.g. user agent), the Catalyst View would probably need a patch to with a configuration switch to populate X-JSON instead of the response body. For now, I'm using JSON::Syck directly. The following are the minimal calls to use. If you have UTF-8 output, see C::V::JSON for UTF-8 encoding.&lt;/p&gt;

&lt;pre&gt;$c-&gt;res-&gt;header(
    'X-JSON' =&gt; JSON::Syck::Dump( \%args );
);&lt;/pre&gt;

&lt;p&gt;I've put together some example code that I thought would be better placed on the wiki. It can be found at: &lt;a href="http://www.dev411.com/wiki/Prototype.js%2C_JSON_and_Catalyst"&gt;Prototype.js, JSON and Catalyst&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;UPDATE: After running into the &lt;a href="/blog/2006/06/01/prototype-x-json-fails-on-long-value-in-ie"&gt;IE max header length issue&lt;/a&gt;, I've decided to put the JSON object in the response body and manually eval request.responseText on the client.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;I use the prototype.js library (aka prototype) for AJAX and recently moved to using JSON to return multiple elements instead of a single one. I had to rearchitect my client request code and my server code to handle JSON but it's worth it to minimize the number of HTTP requests. I use Catalyst and JSON::Syck which make generating the JSON response on the server-side very easy.&lt;/p&gt;

&lt;p&gt;Prototype.js is interesting in that it auto-evals a JSON object that's placed in the X-JSON header instead of the response body like other libaries such as Dojo Toolkit. This allows you to send HTML in the response body but I'm not convinced this is a good implementation since it supports only one HTML fragment in the response body. I think it would be better to simply put the JSON object in the response body and have all the HTML fragments in the JSON object. I just seems cleaner to put all the HTML fragments in JSON instead of fragment 1 in the response body and fragments 2-n in JSON. Although I have the X-JSON header working, I may just move to the more standard JSON in response body approach and eval the JSON string myself. To read the auto-evaled JSON response, the following example expects a JSON associative array and displays the value of the myItem key (more code is available in the wiki link below):&lt;/p&gt;

&lt;pre&gt;onComplete: function( request, json ) {
    alert( json.myItem );
}&lt;/pre&gt;

&lt;p&gt;On the server-side, I use the Catalyst framework to set the header and JSON::Syck to transform Perl data structures to JSON. JSON::Syck is a wrapper around the C libsyck library and very fast. There is a view, Catalyst::View::JSON, however it puts the JSON string in the response body because that is what Dojo and other libraries expect. Since AJAX libraries don't idnetify themselves in anyway to the server (e.g. user agent), the Catalyst View would probably need a patch to with a configuration switch to populate X-JSON instead of the response body. For now, I'm using JSON::Syck directly. The following are the minimal calls to use. If you have UTF-8 output, see C::V::JSON for UTF-8 encoding.&lt;/p&gt;

&lt;pre&gt;$c-&gt;res-&gt;header(
    'X-JSON' =&gt; JSON::Syck::Dump( \%args );
);&lt;/pre&gt;

&lt;p&gt;I've put together some example code that I thought would be better placed on the wiki. It can be found at: &lt;a href="http://www.dev411.com/wiki/Prototype.js%2C_JSON_and_Catalyst"&gt;Prototype.js, JSON and Catalyst&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;UPDATE: After running into the &lt;a href="/blog/2006/06/01/prototype-x-json-fails-on-long-value-in-ie"&gt;IE max header length issue&lt;/a&gt;, I've decided to put the JSON object in the response body and manually eval request.responseText on the client.&lt;/p&gt;

</content>
  </entry>
</feed>

