- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
它说到处都可以使用 CDN,例如 Google 或 Microsoft 的 AJAX CDN 来加载静态脚本库,例如我的 jQuery。
我不明白这对提高我的网站速度有何帮助。在 firebug 中,当我加载 jQuery 时,Google 和 Microsoft AJAX 服务器的时间都在 300 毫秒左右,而在 Chrome 中,我的时间大约为 100 毫秒(不知道是什么造成了差异,没有进行下载,都尝试了几次,但无论如何这不是重点),我的站点在部署时估计平均响应时间为 30 到 40 毫秒。 CDN 加载文件对我的网站有什么好处?这会让一切变得更糟!
我知道当我使用来自 Google CDN 的 jQuery 访问许多网站时,它必须在很长一段时间内只“下载”一次脚本,但我的浏览器仍会尝试连接到 Google 的服务器,并且请求脚本文件,然后收到 304 not modified 状态码。在这个 200 毫秒的往返行程中(Chrome 和 FF 的平均值),我等待。但如果我自己托管脚本文件,那么它将(下载)加载速度更快,大约五倍,这是用户体验的一个重要因素。也许 200 毫秒不是一个很大的交易,但它仍然是一个区别,我想知道为什么建议使用 CDN 而不是我们自己托管文件。最后,在一次性加载后,浏览器也会为我的网站缓存脚本,如果我使用 CDN,浏览器会向 CDN 请求脚本,这会滞后我的网站。
更新:我来自土耳其,这可能是往返次数较多的主要原因。我的大部分访问者都来自这里,所以我想问的是,这对托管在土耳其服务器上的我的网站以及同样位于土耳其,使用 CDN。绝对不适合往返,但也许我错过了一些东西。
最佳答案
两部分答案:
I understand that when I visit many sites using, say, jQuery from Google's CDN, it will have to "download" the script only once for a very long time, but my browser still tries to connect to the Google's server, and ask for the script file, and then receive 304 not modified status code.
它不应该,如果它尊重 Cache-Control
header 则不应该:
Cache-Control:public, max-age=31536000
...which says from the date on the resource, the browser can cache it for up to a year. No need for any HTTP request at all (and that's what I see in Chrome unless I force it, no request at all, just a note saying "from cache"; fired up Firefox and made sure Firebug was on for all pages, came to StackOverflow for the first time in a long time with Firefox [which I only use for testing], and sure enough, it didn't issue any request for jquery at all).
E.g., maybe it takes 200ms for a 304 response, but if your browser is caching correctly, it'll be 0ms for a load-from-cache.
The full set of relevant headers I see on a forced request are:
Cache-Control:public, max-age=31536000Date:Wed, 17 Aug 2011 21:56:52 GMTExpires:Thu, 16 Aug 2012 21:56:52 GMTLast-Modified:Fri, 01 Apr 2011 21:23:55 GMT
...so my browser shouldn't have to request that path again for nearly a year.
See @Dave Ward's comment below: To get max caching results, use the full release number, e.g.:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'></script>
<!-- very specific ---^^^^^ -->
而不是
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
<!-- very generic ----^ -->
这完全取决于您。即使有这样的回退:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
<script>
if (typeof jQuery === "undefined") {
document.write("<scr" + "ipt src='/my/local/jquery.js'></scr" + "ipt>");
}
</script>
...或类似的,如果 CDN 出现故障,用户体验将糟糕。浏览器将尝试连接它很长时间。这种回退只有在 CDN 快速回复失败时才有用,而这是不太可能的。
这意味着如果 Google 的 CDN 出现故障,您将不得不快速调整您所提供的服务以使用本地副本。因此,通过服务器级别的故障转移来开始使用本地路径提供页面服务,从而防御这种情况成为(谷歌服务器的监控事件;不要过度,否则他们会不高兴)。 (或者微软的路径,理论上谷歌和微软可能不会共享底层 CDN 技术,因为他们相处得很好。)
对我来说,大多数网站的答案可能是:继续使用 CDN,当 Google 的图书馆 CDN 出现故障时使用react。另一方面是:如果您对从您的服务器加载它的整体页面加载性能感到满意,那么这样做没有什么害处,直到或除非流量足够高以至于您希望从事物中获得最后一点性能。但是很多(很多很多)网站都依赖于 Google 的 CDN,如果它出现故障,您的网站将远非唯一失败的...
关于javascript - 为 jQuery(或其他静态文件/脚本)使用 CDN 真的是个好主意吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7165156/
如何使用 CDN 将语义 UI 包含到 HTML 页面? CDN链接为https://cdnjs.com/libraries/semantic-ui ,但是怎么使用呢? 最佳答案 您只需复制要用于语义
我有一个我似乎无法解决的特定用例。 典型的 gcloud 设置: K8S集群 一个 gcloud 存储桶 gcloud 负载均衡器 我设法获得了我的域 https://cdn.foobar.com/u
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我有 blob 存储和 CDN 端点,用于存储我的静态内容。 现在我想更新 app.js 文件,因为它被修改了,但是当我将此文件写入 blob 时,CDN 仍然给我旧的 app.js 文件。如何更新我
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
出于性能原因,我希望通过 Azure CDN 提供很少更改的内容。但是,当内容确实发生变化时,更新的数据立即可用很重要。理想情况下,我可以设置一个长 TTL,然后在我更新内容时主动告诉 CDN 使内容
以下main.js代码不遵守优先级顺序(有时underscore.js在backbone.js需要时不会加载它): require({ baseUrl:'/scripts', prio
为什么我不能重用以前删除的端点的名称?例如,如果我创建一个名为“acme-cdn1”的端点,将其删除,然后尝试创建一个具有相同名称的新端点,我会收到以下消息:“错误,该端点名称已经存在。”是否有必要删
我不确定我是否使用 CDN 还是本地。本地是否意味着jquery资源需要安装在智能手机上,以便离线应用程序成为可能? 最佳答案 在这种情况下,本地意味着您自己托管文件(作为网站的一部分),而不是依赖
一种不言自明的问题:为什么建议从 CDN 加载 jQuery 或任何其他库? 最佳答案 CDN 将比您的服务器更快。 服务器具有最大连接数。浏览器将同时请求的数量限制在单个域中。将您的库卸载到 CDN
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我知道 Google AMP 缓存会缓存网站的有效 AMP 页面和资源文件,并通过 .cdn.ampproject.org/提供它们。我做了一些测试,它对我的网站运行良好。 我在一家受欢迎的网站工
我有一个用静态 html/js/css 编写的 HTML5 应用程序(它实际上是用 Dart 编写的,但会编译成 javascript)。我通过 CDN 提供应用程序文件,REST api 托管在一个
我不太确定如何防止谷歌将我的 CDN 域与我的主域名混合编入索引。我想在直接访问 CDN 域时通过 .htaccess 重定向到主域。 事实: 两个域都指向文件系统中的同一个位置。 两者共享相同的 r
引自此处:https://www.ampproject.org/docs/get_started/about-amp.html AMP is a way to build web pages for
我刚刚尝试设置 Azure CDN 帐户,到目前为止(现在已经持续了四个小时)我还无法让它返回除 400 和 404 错误之外的任何内容。 如果这是一个真正的 CDN,我需要做的就是将 CDN 指向我
我们希望提供来自少数可用 AWS 区域的大量视频文件。目标受众来自全局多个地点。不保证连接速度。因此,绝对需要 CDN(最好是 CloudFront)。 视频需要受到保护,因此只有在用户经过身份验证和
有没有content delivery network (CDN)正在托管google-code-prettify ? 我正在 TypePad 上建立一个博客如果可能的话,希望利用 CDN。 最佳答案
在我的应用程序中,使用 ember-cli 开发,我还需要一些外部资源,例如 bootstrap;现在我通过 Brocfile 导入它: app.import('bower_components/bo
我想知道是否有像 960GS 这样的 CSS 框架的 CDN。因为我认为很多人都在使用它。 最佳答案 我还没有尝试过 cachedcommons.org,但他们有一个 960 的链接,听起来像你所要求
我是一名优秀的程序员,十分优秀!