Why does Disqus not use global CDN for it's comment code?

眉间皱痕 提交于 2019-12-10 10:18:56

问题


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);
}());

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 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?


回答1:


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

If <shortname> exists

http://<shortname>.disqus.com/count.js redirects to something like

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.

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.



来源:https://stackoverflow.com/questions/10097347/why-does-disqus-not-use-global-cdn-for-its-comment-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!