Skip to content

Instantly share code, notes, and snippets.

@willnode
Forked from nternetinspired/gist:7482445
Last active February 5, 2018 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willnode/052cc2f0b0115c7e4041a7792c6ba8d3 to your computer and use it in GitHub Desktop.
Save willnode/052cc2f0b0115c7e4041a7792c6ba8d3 to your computer and use it in GitHub Desktop.
Load Disqus comments only on demand if you give a shit about page weight and your visitors.Even with no comments, i.e. an empty comment form, calling Disqus will load an extra 226Kb. If your page has comments this can be far higher.This Gist accompanies my blog post: http://internet-inspired.com/wrote/load-disqus-on-demand/
var disqus_config = function () {
// Disqus config here
};
var show_disqus = document.getElementById('show-disqus');
show_disqus.onclick = function() {
show_disqus.textContent = 'Loading...';
// OR
show_disqus.parentNode.removeChild(show_disqus);
var d = document, s = d.createElement('script');
var shortname = 'YOUR-DISQUS-USERNAME'; // enter your disqus username here
s.src = 'https://' + shortname + '.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
};
<!-- The button to open comments is inside disqus_thread so it get automatically replaced when Disqus loaded -->
<div id="disqus_thread"><button id="show-disqus">Show Comments</button></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment