3

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?

ajax333221
  • 11,436
  • 16
  • 61
  • 95
Alex Grin
  • 8,121
  • 6
  • 33
  • 57

1 Answers1

8

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.

stewe
  • 41,820
  • 13
  • 79
  • 75
  • But I suppose the client will not be able to cache the JS file between different sites, since it is requested using different subdomains. – David Hellsing Apr 11 '12 at 06:45
  • The JS file itself will be cached between different domains, the only thing which gets not cached between domains is the redirect. – stewe Apr 11 '12 at 13:52
  • Thanks for the explanation. I did not realize that browsers would cache the file after the redirect. – Alex Grin Apr 11 '12 at 16:05