Ten Little Comments

Once upon a time, there were ten little comments who used to play around in the kreuzwerker domain.
Diego Caponera


Once upon a time, there were ten little comments who used to play around in the kreuzwerker domain. They were growing up wealthy and strong, when all of a sudden Lady Fanny claimed their departure.

With all the concern, we gathered in the council hall and asked sage Maester Joern if he could have any ideas about what may have happened to them: we looked into all locations they used to show, but the search was unfruitful.

Then all of a sudden, the memory of a previous reading came to my mind - the mighty beast Disqus, which was defeated ages ago, may have been haunting our realm again.

As any legendary creature, it was famous for both tormenting its victims with fierce distress and providing them with inextricable riddles:

You will get the tasty little comments in your sack,
if you put the original URL back!

After the brief puzzlement due to a medieval beast knowing what a URL is, we started our investigation.

(Technical) Story

I think that the reason why Disqus became one of the de facto standards of online commenting is its installation ease; as it lives into an <amp-iframe sandbox="allow-scripts allow-same-origin" layout="responsive" frameborder="0"></amp-iframe>, you can just put the following snippet of code into your page et voilá, les jeux sont faits:

<div id="disqus_thread"></div>
<script type="text/javascript">
    var disqus_shortname = ''; // required: replace example with your forum shortname

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

How does then Disqus know how to retrieve the proper comments for a given page? It just checks verbatim the url of the current document, for instance:


Some months ago we changed our server configuration, from Apache to nginx, and we added a rule that removed the .html extensions from our documents, so that one would actually browse:


That was preventing Disqus from retrieving the original comments! As we did not want to restore the file extension, we look into Disqus documentation and eventually found that we could provide an unique identifier to the service, in order to get the original comments back:

<script type="text/javascript">
    var disqus_shortname = 'kreuzwerker';
    var disqus_url = '<%= @absoluteUrl(@post.url) %>';
    // ...

This kept our document model consistent with the one that Disqus was aware of, and the ten little comments were finally back!

Sidequest: the evil Disqus “Also on” box

Screen Shot 2018-06-13 at 14.37.29

Comments were back, but if you clicked on one of the links on the bottom Disqus box, you got redirected to the homepage, and not the post itself!

This happened because we got rid of the www subdomain in the server configuration, routing thus all traffic going to https://www.kreuzwerker.de to https://kreuzwerker.de/, regardless of the original path (which was a bad idea, of course).

Solution: (re)introduce the rule into nginx configuration, thanks to our resolute knight Martin:

server {

  include /etc/nginx/enforce-ssl.conf;
  server_name www.kreuzwerker.de kreuzwerker.de;



Aftermath (aka tl;dr)

As a bottom line, always remember to:

  • set up the Disqus snippet with a unique id (either the URL of the page, or a numeric ID of your document);
  • set up any server redirection configuration in order not to interfere with the URL stored by Disqus in the evil bottom box (which is not evil at all, may we have its forgiveness).

Comments are welcome, in case you want to join the ten little ones.