Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 976
Alex Grin Avatar asked Nov 20 '25 03:11

Alex Grin


1 Answers

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.

like image 136
stewe Avatar answered Nov 21 '25 16:11

stewe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!