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?

thorn0
  • 9,362
  • 3
  • 68
  • 96
Xavi
  • 20,111
  • 14
  • 72
  • 63

5 Answers5

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.

David
  • 8,340
  • 7
  • 49
  • 71
  • @Xavi: not on CDNJS. You could suggest it on the cdnjs website – David Apr 11 '11 at 08:20
  • cdnjs looks like a very cool initiative! The guys are super responsive to feedback, too. Thanks for pointing this out. – webmat Apr 27 '11 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 '11 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; https://github.com/douglascrockford/JSON-js/raw/master/json2.js lol can you not put new line characters in comments? – Thomas Davis May 12 '11 at 01: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 '11 at 22:51
  • @ThomasDavis http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.min.js seems to be there now. Ok to use right? – ryanve Feb 16 '12 at 03:30
  • @Dve Do you know if this is a globally support site (cdnjs)? Just wondering because certain CDNs are blocked by companies, found that out the hard way with Amazons cloudfront CDN.. – Mark Pieszak - Trilon.io Mar 11 '13 at 14:49
  • @mcpDESIGNS Its powered by CloudFlare, so I would expect it to be. But I dont know for certain – David Mar 11 '13 at 15:13
  • Dve, may I suggest not to hard-link libs with a specific version number, but to link to the http://cdnjs.com/ homepage, then people can grab the newest link themselves? Also, CDNJS [suggests](http://paulirish.com/2010/the-protocol-relative-url/) to drop the ```http:``` I'm going to suggest use of a /latest/ folder to help mitigate this issue later. . @Dimskiy Try the other versions here; they are not usually recommended, but might help you out? https://github.com/douglascrockford/JSON-js – tomByrer May 30 '13 at 23:38
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.

thorn0
  • 9,362
  • 3
  • 68
  • 96
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.

Andrew
  • 14,204
  • 15
  • 60
  • 104
  • 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 08 '10 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

Thomas Davis
  • 1,886
  • 15
  • 14
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.

DannyLane
  • 2,096
  • 1
  • 16
  • 17
  • Should the https be http for pages which are not serving content securely? i.e. not "mixing secure and insecure content"? – Shaggy Frog May 03 '11 at 05: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: http://stackoverflow.com/questions/5502540/should-github-be-used-as-a-cdn-for-javascript-libraries – DannyLane May 19 '11 at 09: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 – Web_Designer Jan 15 '12 at 08:11
  • @DannyLane, you should edit your answer with the info about not using GitHub as a CDN for JS. – asymmetric Oct 24 '12 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 '14 at 14:46