标签云

微信群

扫码加入我们

WeChat QR Code

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?


Is there a minified version?

2019年04月22日14分06秒

Xavi: not on CDNJS. You could suggest it on the cdnjs website

2019年04月22日14分06秒

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?

2019年04月22日14分06秒

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.

2019年04月22日14分06秒

tomByrer answer updated

2019年04月22日14分06秒

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. =(

2019年04月22日14分06秒

Should the https be http for pages which are not serving content securely? i.e. not "mixing secure and insecure content"?

2019年04月22日14分06秒

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/…

2019年04月22日14分06秒

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

2019年04月22日14分06秒

DannyLane, you should edit your answer with the info about not using GitHub as a CDN for JS.

2019年04月22日14分06秒

Not sure why this answer is getting downvoted recently, I corrected it to say not to use this method almost 3 years ago.

2019年04月22日14分06秒