Load Disqus On Click

Posted by Weston Ganger

You can increase the load times on your pages by letting the user choose when to load Disqus comments. You can place this on a button or link or whatever


<div id="comments">
  <button id="show-comments" type="button">Show Comments</button>
  <div id="disqus_thread"></div>
</div>

$(function(){
  $('#show-comments').on('click', function(){
    var disqus_shortname = 'your_disqus_user_name';

    (function() {
      var disqus = document.createElement('script'); 
      disqus.type = 'text/javascript'; 
      disqus.async = true;
      disqus.src = '//' + disqus_shortname + '.disqus.com/embed.js';
      (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(disqus);
    })();

    $(this).hide(); // Hide the button
  });
});


Related External Links:

Article Topic:Software Development - Javascript

Date:September 07, 2015

Recommended Posts