Github应该用作javascript库的CDN吗? [英] Should Github be used as a CDN for javascript libraries?

查看:155
本文介绍了Github应该用作javascript库的CDN吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从CDN而不是您自己的服务器提供javascript库具有巨大的优势。减少服务器的工作量,CDN可能会比服务器更接近用户,但最重要的是用户的浏览器很可能已经从该URL缓存了它。最后一个意味着每个人的总工作量减少,所以它显然是一个全面的胜利,更有可能我们(开发人员)更多地依靠CDN来提供我们的javascript。

Serving javascript libraries from a CDN instead of your own server comes with tremendous advantages. Less work for your server, possibility for the CDN to have a copy closer to the user than your server, but most importantly a good chance that your user's browser already has it cached from that URL. The last one means less total work for everybody, so it's clearly a win all around, and is more likely the more often we (developers) rely on the CDNs to serve our javascript.

但是流行的javascript CDN(谷歌,微软,其他?)只托管少量文件。对于其他人,我们可以选择自己托管它们,或者......使用源代码控制服务器作为一种CDN。 Github或类似网站不太可能具有针对全球服务进行优化的地理分布式文件缓存。但是,如果这是常见的做法,那么用户的浏览器就有可能将其缓存。从我们的服务器到github的卸载工作的论点只有在Github愿意自愿这样做的情况下才有效。

But the popular javascript CDNs (Google, Microsoft, others?) only host a small number of files. For others we have the choice of hosting them ourselves, or ... using the source control server as a kind of CDN. It's unlikely Github or similar has a geographically distributed cache of files optimized for serving globally. But if it's common practice, then there is a decent chance that the user's browser will have it cached. The argument of off-loading work from our servers to github is only valid if Github has willingly volunteered to do this.

那么,这是常见做法吗?我们应该互相鼓励这样做吗? Github介意吗?他们是否已制定官方政策?

So, is it common practice? Should we encourage each other to do this? Does Github mind? Do they have an official policy stated?

推荐答案

如果您关心性能或IE9兼容性,则不应对JavaScript文件执行此操作。

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

GitHub不会使用远期过期标头提供其原始文件。如果没有跨站点缓存的可能性,您将失去使用公共CDN托管JavaScript的最大好处。实际上,在每个用户第一次请求文件后,使用GitHub作为CDN将比在自己的服务器上简单托管文件慢(假设您在服务器上正确配置了缓存)。

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).

另一个问题是GitHub不提供带有与文件实际MIME类型匹配的内容类型标头的原始文件。在IE9(可能还有其他浏览器/代理/防火墙/等)中,默认情况下会阻止未使用正确内容类型提供的JavaScript文件。您可以在BlockUI演示页面上看到该操作,例如:

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:

这篇关于Github应该用作javascript库的CDN吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆