为什么Disqus不使用全局CDN作为评论代码? [英] Why does Disqus not use global CDN for it's comment code?

查看:88
本文介绍了为什么Disqus不使用全局CDN作为评论代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Disqus 评论代码说明,你应该包括他们的JavaScript如下:

According to the Disqus comment code instructions, you're supposed to include their JavaScript as follows:

(function () {
  var s = document.createElement('script');
  s.async = true;
  s.type = 'text/javascript';
  s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
  (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());

JavaScript的位置基于特定于您网站的短名称。为什么Disqus会这样做而不是为他们的JavaScript使用一个全局位置(例如cdn.disqus.com/count.js)。如果每个站点的JavaScript都相同,那么要求每个人为他们访问的每个支持Disqus的域重新下载JavaScript似乎很愚蠢。如果基于短名称JavaScript是不同的,为什么不使用在加载全局js之前设置的短名称变量?

The location of the JavaScript is based on a shortname that is specific to your site. Why does Disqus do that instead of using one global location for their JavaScript (e.g. cdn.disqus.com/count.js). If the JavaScript is the same for each site, it seems silly to require everyone to redownload the JavaScript for each Disqus-enabled domain they visit. If the JavaScript is different based on the shortname, why not just use a shortname variable that gets set before the global js is loaded?

Disqus是一个相当大而复杂的公司所以我假设这是他们有意识和有目的的决定。为什么他们走这条路?

Disqus is a fairly large and sophisticated company, so I'm assuming that this is a conscious and purposeful decision on their part. Why did they go this route?

推荐答案

实际上他们正在使用CDN来提供 count.js

Actually they are using a CDN to deliver count.js.

如果< shortname> 存在

http://< shortname> .disqus.com / count.js 重定向到类似

http://mediacdn.disqus.com/1334018047/build/system/count.js

减少流量 count.js (在CDN上)附带一个Expires-Header,允许将其缓存一个月。

To reduce traffic count.js(on the CDN) is delivered with an Expires-Header that allows caching it up to a month.

但是想象一下,他们需要更改代码或阻止某些网站或向其他人提供特殊功能,这需要一个月的时间才能让所有客户获得更改。为了减少这个时间跨度,他们可能会使用此重定向(缓存最多只能持续10分钟),因此代码/功能更改将在10分钟内到达每个客户端。

But imagine they need to change the code or block some sites or deliver special features to others, it would take up to a month until all clients get the changes. To reduce that timespan they probably use this redirect (which is cached for only up to 10 minutes), so code/feature changes will reach every client within 10 minutes.

它为他们提供了很大的灵活性,并且不需要用户更改包含代码。

It gives them a lot of flexibility and does not require the user to change the include code ever.

这篇关于为什么Disqus不使用全局CDN作为评论代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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