Disqus is a popular comment management system for blog or website. But it take time to load and increase page load time of website. In this post I'm telling you how to load disqus comment only when visitor want to add or view comment. Initially display only button or link, labeled with Add a comment or Post a comment, when someone click on that link/button then disqus comment will start to load.
Use CSS for customizing button style.
Why ?
- This will decrease the page load time, and speed up your website or blog.
- Decrease the comment spamming.
<div id='disqus_thread'/>
<div id='disqus_loader' style='text-align: center'>
<button class='disqusbutton' onclick='load_disqus()'>Add comment</button>
<script>
function load_disqus()
{
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = "http://YOUR-DISQUS-SHORT-NAME.disqus.com/embed.js";
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
var ldr = document.getElementById('disqus_loader');
ldr.parentNode.removeChild(ldr);
}
</script>
</div>
YOUR-DISQUS-SHORT-NAME
replace with your disqus short name.Use CSS for customizing button style.
.disqusbutton{
font-family:Verdana, Geneva, sans-serif;
font-size:14px;
text-transform:capitalize;
background-color:#06C;
color:#f9f9f9;
text-outline:#000;
font-weight:900;
padding:7px;
border-radius:8px;
cursor:pointer;
}