问题
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