Should Github be used as a CDN for javascript libraries? [closed]

萝らか妹 提交于 2019-11-26 14:30:58

You should not do that for JavaScript files if you care about performance or IE9 compatibility.

GitHub doesn't serve its "raw" files with a far-future expires header. Without the possibility of cross-site caching, you lose the biggest benefit of using a public CDN to host your JavaScript. In fact, using GitHub as a CDN will be slower than simply hosting the files on your own server after each user's first request for the file (assuming you configure caching correctly on your server).

Another problem is that GitHub doesn't serve "raw" files with a content-type header that matches the file's actual MIME type. In IE9 (and perhaps other browsers/proxies/firewalls/etc), JavaScript files that aren't served with the correct content-type are blocked by default. You can see that in action on the BlockUI demo page, for example:

Chris Jacob

Linking to GitHub "raw" files has some issues as outlined by Dave Ward's answer.

I suggest you look into GitHub Pages as an option.

Read this article:
GitHub as a CDN. Cache your Javascripts, Stylesheets and Web Assets with GitHub Pages.

This was recently asked in github's support forums, and the official answer was that it's ok.

Having said that, I agree with other answers: github was never really meant to be a CDN, while Google and Microsoft have specific infrastructure for that.

It's fine for prototyping / personal stuff, but for production I would look at:

http://www.cdnjs.com/

http://cachedcommons.org/ -- no longer available

I'm doing it for months now, had some concerns first but it's totally cool if you have no problems with your files being publicly available, use minified versions if you care.

But still - Google & MS rule the space for jQuery & jQuery Templates - so I use them for that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!