用于 jQuery 或 Google CDN 的 Microsoft CDN? [英] Microsoft CDN for jQuery or Google CDN?

查看:25
本文介绍了用于 jQuery 或 Google CDN 的 Microsoft CDN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您使用哪个 CDN 链接到您的 jquery 文件或任何 javascript 文件实际上是否重要.一个可能比另一个更快吗?还有哪些其他因素会影响您决定使用 CDN?我知道微软、雅虎和谷歌现在都有 CDN.

Does it actually matter which CDN you use to link to your jquery file or any javascript file for that matter. Is one potentially faster than the other? What other factors could play a role in which cdn you decide to use? I know that Microsoft, Yahoo, and Google all have CDN's now.

推荐答案

根据评论更新:

简短版本:这无关紧要,但可能取决于他们托管的内容.它们都托管不同的东西:Google 不托管 jQuery.Validate,Microsoft 不托管 jQuery-UI,自 2016 年以来他们托管了!!,Microsoft 提供了他们的脚本,否则这些脚本将通过 ScriptResource.axd 提供和更简单的集成(例如 带有 ASP.Net 4.0 的 ScriptManager).

Short version: It doesn't matter much, but it may depend on what they host. They all host different things: Google doesn't host jQuery.Validate, Microsoft did not host jQuery-UI, since 2016 they do!!, Microsoft offers their scripts that would otherwise be served via ScriptResource.axd and an easier integration (e.g. ScriptManager with ASP.Net 4.0).

重要说明:如果您正在构建 Intranet 应用程序,请远离 CDN 方法.谁托管它并不重要,除非您在内部非常超载的服务器上,否则没有 CDN 可以为您提供比本地 100mb/1GB 以太网更高的性能.如果您将 CDN 用于严格的内部应用程序,则会损害性能.正确设置缓存过期标头并忽略内网中存在的 CDN- 唯一的场景.

Important Note: If you're building an intranet application, stay away from the CDN approach. It doesn't matter who's hosting it, unless you're on a very overloaded server internally, no CDN will give you more performance than local 100mb/1GB ethernet will. If you use a CDN for a strictly internal application you're hurting performance. Set your cache expiration headers correctly and ignore CDNs exist in the intranet-only scenario.

任何一个被屏蔽的可能性似乎都差不多,几乎为零.我曾处理过不正确的合同,但这似乎是一个例外.此外,自从这个答案最初发布以来,围绕它的上下文已经发生了很大变化,Microsoft CDN 取得了很大进展.

The chances of either being blocked seems to be about equal, almost zero. I have worked on contracts where this isn't true, but it seems to be an exception. Also, since the original posting of this answer, the context surrounding it has changed greatly, the Microsoft CDN has made a lot of progress.

我目前参与的项目使用最适合我们解决方案的两种 CDN.有几个因素在起作用.使用旧浏览器的用户可能仍会为每个域同时发出 2 个请求 按照 HTTP 规范的建议.对于任何运行支持流水线(当前所有浏览器)的新东西的人来说,这都不是问题,但基于另一个因素,我们也将消除此限制,至少在 javascript 方面是这样.

The project I'm currently on uses both CDNs which works best for our solution. Several factors play into this. Users with an older browser are still probably making 2 simultaneous requests per domain as recommended by the HTTP specification. This isn't an issue for anyone running anything decently new that supports pipelining (every current browser), but based on another factor we're knocking out this limitation as well, at least as far as the javascript.

我们使用的 Google CDN:

Google's CDN we're using for:

我们使用的微软 CDN:

Microsoft's CDN we're using for:

  • MicrosoftAjax.js
  • MicrosoftAjaxWebForms.js (until 4.0 we're not completely removing all UpdatePanels)
  • jQuery.Validate.min.js

我们的服务器:

  • Combined.js?v=2.2.0.6190(Major.Minor.Iteration.Changeset)

由于我们构建过程的一部分是组合和缩小所有自定义 javascript,我们通过自定义脚本管理器执行此操作,该管理器包含这些脚本的发布或调试(非缩小)版本,具体取决于构建.由于 Google 不托管 jQuery 验证包,因此这可能是一个缺点.MVC 在他们的 2.0 版本中包含/使用它,所以你可以完全依赖微软的 CDN 来满足你的所有需求,并且所有这些都通过 ScriptManager 自动.

Since part of our build process is combining and minifying all custom javascript, we do this via a custom script manager that includes the release or debug (non-minified) versions of these scripts depending on the build. Since Google doesn't host the jQuery validation package, this can be a down-side. MVC is including/using this in their 2.0 release, so you could rely completely on Microsoft's CDN for all your needs, and all of it automatic via the ScriptManager.

唯一要提出的另一个论点是 DNS 时间,这在页面加载速度方面是有代价的.平均:仅仅因为它被使用得更多(使用时间更长)ajax.googleapis.com 很可能比 ajax.microsoft.com 更早被 DNS 返回,仅仅是因为本地 DNS 服务器更有可能收到它的请求(这是该区域的第一个用户的惩罚).这是一件非常的小事,只有在性能极其重要时才应考虑,精确到毫秒.
(是的:我意识到这一点与我同时使用两个 CDN 相悖,但在我们的例子中,DNS 时间远远被 javascript/阻塞发生的等待时间所掩盖)

The only other argument to be made would be DNS times, there is a cost to this in terms of page load speed. On Average: Simply because it's used more (it's been around longer) ajax.googleapis.com is likely to be returned by DNS sooner than ajax.microsoft.com, simply because the local DNS server was more likely to get a request for it (this is a first user in the area penalty). This is a very minor thing and should only be considered if performance is extremely important, down to the millisecond.
(Yes: I realize this point is contrary to my using both CDNs, but in our case the DNS time is far overshadowed by the wait time on the javascript/blocking that occurs)

最后,如果您还没有看过它,最好的工具之一是 Firebug,还有一些它的插件:Page SpeedYSlow.如果您使用 CDN,但您的页面由于没有缓存头而每次都请求图像,那么您就错过了唾手可得的果实.Firebug 的 Net 面板可以快速为您提供页面加载时间的快速细分,Page Speed/YSlow 可以提供一些很好的建议来提供帮助.

Last, if you haven't looked at it, one of the best tools out there is Firebug, and some plug-ins for it: Page Speed and YSlow. If you use a CDN but your pages are requesting images every time because of no cache-headers, you're missing the low-hanging fruit. Firebug's Net panel can quickly give you a quick breakdown of your page load-time, and Page Speed/YSlow can offer some good suggestions to help.

这篇关于用于 jQuery 或 Google CDN 的 Microsoft CDN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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