admin管理员组文章数量:1336660
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.
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.
Share Improve this question asked Nov 17, 2008 at 19:51 user38339user38339 3651 gold badge3 silver badges10 bronze badges5 Answers
Reset to default 3I just found a JSON parser, json2.js, at json 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 pete with this approach, though.
There are quite a few javascript frameworks out there in addition to Mootools that can acplish what you're looking for. I remend 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./
http://www.prototypejs/
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 mon finish-handler. Each request is individual.
Two suggestions:
- Find a library that breaks the functionality you need down into relatively small ponents. Then download only the ponents 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
- Find the functionality you need in one of the open source libraries and refactor it into your own significantly smaller version.
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 pression option, the file size came out to 33.8KB.
本文标签: javascriptWhat is the bestlightweight JSONajax scriptStack Overflow
版权声明:本文标题:javascript - What is the best, light-weight JSONajax script? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742415023a2470550.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论