78

It's well known that Google and Microsoft host several common javascript libraries on their CDNs (content distribution networks). Unfortunately neither seems to host JSON2.js.

I'm aware that I could upload a copy of JSON2.js to my server and serve it myself, but there are a number advantages CDNs offer that I would like to take advantage of.

So with that in mind, are there any publicly available CDNs that host JSON2? If not, any idea why? Is there some sort of copyright reason?

5 Answers 5

60

Checkout cdnjs.com

http://cdnjs.com/libraries/json2/

Might also be worth investigating Json3

http://cdnjs.com/libraries/json3/

UPDATE: Some of the information was out of date, changed to better links.

9
  • @Xavi: not on CDNJS. You could suggest it on the cdnjs website
    – David
    Apr 11, 2011 at 8:20
  • cdnjs looks like a very cool initiative! The guys are super responsive to feedback, too. Thanks for pointing this out.
    – webmat
    Apr 27, 2011 at 15:03
  • webmat: No worries. Its a great idea. I have been using it for a while now. haven't seen any downtime either.
    – David
    Apr 27, 2011 at 15:12
  • 12
    Thomas from cdnjs.com here with two quick reasons why there is no minified version. 1) The script may not possibly function as the author intended using the method of minification we choose. 2) As a security step we ensure that all files checksums match the original authors hosted files so community submitted updates cannot contain malformed minified code. So for now that leaves us hosting Crockfords hosted un-minified version; github.com/douglascrockford/JSON-js/raw/master/json2.js lol can you not put new line characters in comments? May 12, 2011 at 1:44
  • 3
    Just FYI: I served json2 from cdnjs.com in my recent project. I got the link for it from this very stackoverflow page. Some of the IEs out there did not like this. I wasn't able to figure out why as these were all different versions from 7 to 9. Some IEs were interpreting json2 in KOI-7 format. As a result, the users were getting JavaScript error: "JSON is not defined". I tried setting @charset attribute of script tag to UTF-8 and it didn't solve the problem. My fix was to serve json2 together with my other js files. (Compressed and minified). Feel free to contact me if you have questions.
    – Dimskiy
    Jul 28, 2011 at 22:51
19

json2.js can be found on Yandex CDN servers.

Full version: http://yandex.st/json2/2011-10-19/json2.js

Minified: http://yandex.st/json2/2011-10-19/json2.min.js

HTTPS also works.

5

I think probably it's too early to expect the big CDNs to start doing this. When enough sites are using a library, the benefits become clear: greater availability, more frequent use, reduced client requests, increased performance for the end user. If only a few sites are using it, chances of client having a copy in their cache already is low and all performance boosts are lost. So all that's left is that MS and Google offset your bandwidth charges, which is not their intention. Thus, the solution is to get more developers to use the library.

Plus the library is so tiny. The code is still only 3.5KB using conservative minification. For comparison, jQuery is 24KB and ext-core is 29KB. I'd personally recommend folding the library into your own site's base JS and get your performance boost there. At least until there's wider acceptance.

Plus, it's funny I'd have expected the JSON library to be hosted also at Yahoo, but I can't find it. I mean Crockford works there.

1
  • Those are fair points. The JSON object is becoming standard in many browsers so the need for JSON2.js declining. Also the library is tiny! It's just that I've gotten into the habit of creating small self-contained JS apps that I can quickly upload or e-mail to people. Every now and I end up using the JSON object. In those cases my JS app either doesn't work in IE6/7 or it's no longer self-contained. =(
    – Xavi
    Jun 8, 2010 at 12:17
4

Thomas from cdnjs.com here with two quick reasons why there is no minified version.

1) The script may not possibly function as the author intended using the method of minification we choose. 2) As a security step we ensure that all files checksums match the original authors hosted files so community submitted updates cannot contain malformed minified code.

So for now that leaves us hosting Crockfords hosted un-minified version; https://github.com/douglascrockford/JSON-js/raw/master/json2.js

2

There is now.

Douglas Crockford recently put JSON2 on github, this url will always link to the most recent version.

Edit: Its not a good idea to use this method, see my comment below.

5
  • Should the https be http for pages which are not serving content securely? i.e. not "mixing secure and insecure content"? May 3, 2011 at 5:06
  • 5
    On second thoughts, I don't think its a good idea to use github as a cdn, see the answer to this question: stackoverflow.com/questions/5502540/…
    – DannyLane
    May 19, 2011 at 9:55
  • 4
    @ShaggyFrog One trick: you can remove the http: or https:, and the script will load using the correct method for that site: //github.com/douglascrockford/JSON-js/raw/master/json2.js Jan 15, 2012 at 8:11
  • @DannyLane, you should edit your answer with the info about not using GitHub as a CDN for JS.
    – asymmetric
    Oct 24, 2012 at 15:29
  • Not sure why this answer is getting downvoted recently, I corrected it to say not to use this method almost 3 years ago.
    – DannyLane
    Feb 10, 2014 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.