tags:

views:

245

answers:

6

I want to know what are the necessary files are required to attach as a Script while writing JQuery or parsing JSON. In some examples I see developers referencing to: jquery-1.3.2.min.js and some use jquery.min.js. For JSON, some use json2.js.

+3  A: 

For jQuery, I would recommend jQuery.js when debugging, and jQuery.min.js once the site is released.

jQuery.min.js is minified, making it much smaller than the original jQuery.js. This makes it faster to download, but much more difficult to debug.

I also recommend loading jQuery from Google's CDN, like this:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.js" />

Loading jQuery from Google's servers removes some of the load from your server.

SLaks
A: 

Hi, I have only just used jquery with asp.net and I've found that there are usually two .js files one which is with all the whitespace and one which is minimised i.e. all the whitespace and linebreaks removed to reduce size. I just reference the jquery-.min.js in my master page and away I go with any derived pages which reference the master. Really cool stuff.

<script type="text/javascript" src="../Javascript/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../Javascript/jquery.blockUI.js"></script>

Cannot comment for the JSON. blockUI is a very handy add-on worth looking at.

Mike
+1  A: 

You don't write JSON code. JSON is a "standard" for representing data. What you do with JSON is parse it so that you get a object which you can then manipulate.

Since you are using jQuery you don't need a seperate JSON parser if you are loading your JSON data with AJAX. If you call $.getJSON() you will get a nice object in your callback. It's as simple as that.

As far as loading jQuery @SLaks gave a nice answer. Use the minifyed version on production to reduce the time it takes for browser to load/parse the file and use the "regular" version while developing so that you can more easily debug if you need to.

Use the latest version that you can get at jQuery.com or link to Google's CDN as @SLaks showed you.

Jan Hančič
+2  A: 

For JSON I recommend using json2.js, as it will provide you with a safe mechanism for deserializing a string to an object and not allow the execution of any malicious code embedded in that string. While the Javascript function eval will work, unless you trust the source of the JSON you could be performing and eval on a function.

David Robbins
+1  A: 

JSON2 is a javascript library that encapulates methods which help create well formated JSON objects. To read about how to use JQuery's ajax functionality, you can read a tutorial here on SitePoint's website. And for further information about the actual API for Jquery's Ajax functionality, here is a link to the API/1.3/Ajax code.

Good luck, and hopes this helps some.

Chris
A: 

@David and @Chris.

Google doesn't seem to do have a CDN link for the JSON 2 library. Is that right? Seems like a slightly strange omission to me (I can understand omitting it from jQuery core, but I'm suprised it's not included in any jQuery packages or in Google's CDN).

Ian Grainger