-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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