According to the Disqus comment code instructions, you're supposed to include their JavaScript as follows:
根据Disqus评论代码说明,您应该包括他们的JavaScript如下:
(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);
}());
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?
JavaScript的位置基于特定于您网站的短名称。为什么Disqus会这样做,而不是为他们的JavaScript使用一个全局位置(例如cdn.disqus.com/count.js)。如果每个站点的JavaScript都相同,那么要求每个人为他们访问的每个支持Disqus的域重新下载JavaScript似乎很愚蠢。如果JavaScript基于短名称不同,为什么不使用在加载全局js之前设置的短名称变量?
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?
Disqus是一家相当庞大而成熟的公司,所以我认为这是他们有意识和有目的的决定。他们为什么要走这条路?
1 个解决方案
#1
8
Actually they are using a CDN to deliver count.js
.
实际上他们正在使用CDN来传递count.js.
If <shortname>
exists
如果
http://<shortname>.disqus.com/count.js
redirects to something like
http://
http://mediacdn.disqus.com/1334018047/build/system/count.js
.
To reduce traffic count.js
(on the CDN) is delivered with an Expires-Header that allows caching it up to a month.
为了减少流量count.js(在CDN上)提供了一个Expires-Header,允许缓存最多一个月。
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.
但是想象一下,他们需要更改代码或阻止某些网站或向其他网站提供特殊功能,这需要一个月的时间才能让所有客户端获得更改。为了减少这个时间跨度,他们可能会使用此重定向(缓存最多只能持续10分钟),因此代码/功能更改将在10分钟内到达每个客户端。
It gives them a lot of flexibility and does not require the user to change the include code ever.
它为他们提供了很大的灵活性,并且不需要用户更改包含代码。
#1
8
Actually they are using a CDN to deliver count.js
.
实际上他们正在使用CDN来传递count.js.
If <shortname>
exists
如果
http://<shortname>.disqus.com/count.js
redirects to something like
http://
http://mediacdn.disqus.com/1334018047/build/system/count.js
.
To reduce traffic count.js
(on the CDN) is delivered with an Expires-Header that allows caching it up to a month.
为了减少流量count.js(在CDN上)提供了一个Expires-Header,允许缓存最多一个月。
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.
但是想象一下,他们需要更改代码或阻止某些网站或向其他网站提供特殊功能,这需要一个月的时间才能让所有客户端获得更改。为了减少这个时间跨度,他们可能会使用此重定向(缓存最多只能持续10分钟),因此代码/功能更改将在10分钟内到达每个客户端。
It gives them a lot of flexibility and does not require the user to change the include code ever.
它为他们提供了很大的灵活性,并且不需要用户更改包含代码。