views:

1160

answers:

5

I am creating a joomla plugin and want to load an array of images after the page has loaded. To do that, I'm currently using mootools.js to call myserver URL, obtain the JSON response and parse the response into javascript variables that represent each image url. It works great, but mootools.js is appropriately named since it is a real heffer in the size department.

Is there a lightweight script out there that will make the ajax call and parse the JSON object? The smaller the better.

+2  A: 

There are quite a few javascript frameworks out there in addition to Mootools that can accomplish what you're looking for. I recommend taking a look at Jquery or Prototype. They're very similar to Mootools and the mini-fied versions may provide the lightweight solution you're looking for:

http://jquery.com/

http://www.prototypejs.org/

Anne Porosoff
A: 

Two suggestions:

  1. Find a library that breaks the functionality you need down into relatively small components. Then download only the components you need. YUI is nicely divided, but even those files can be somewhat larger than necessary. A smaller project that is based on YUI is Fork. Find this library at http://forkjavascript.org
  2. Find the functionality you need in one of the open source libraries and refactor it into your own significantly smaller version.
Benry
A: 

I don't know what particular version of MooTools you're using, but it doesn't have to be large if you tailor it specifically to your needs. MooTools provides an advanced download page that will allow you to create a custom-built, minified version of the library in a single file. Try it out and see if it suits your needs. If it does, you won't have to go and learn prototype/jquery/etc.

Edit: I just tried downloading MooTools' Request.JSON package with all dependencies. With the YUI compression option, the file size came out to 33.8KB.

Joel Wietelmann
A: 

If it's lightweight you want, I can suggest Net.js.

http://xkr.us/code/javascript/Net/

However, it doesn't support parsing of JSON, but that is simply one row of code, getting the responseText and calling eval on it:

var json = eval('(' + xhr.responseText + ')');

Downsides:

Timeout is not configurable. However, easy to modify directly in the source.

No support for a request-group with common finish-handler. Each request is individual.

jishi
+4  A: 

I just found a JSON parser, json2.js, at json.org that minifies down to about 3k. You basically do a standard HTTPRequest via AJAX and then pass the response text to the JSON parser to create the JSON object.

Thanks for all the answers and I did track them all down. I couldn't get any of them small enough to compete with this approach, though.