The comments on my website are powered by Disqus, the most popular commenting platform that offers a lot more features than what the native commenting engines of Blogger or WordPress have to offer. For instance, Disqus lets me moderate discussions or reply to comments via email itself and commenters can use their existing Facebook or Twitter accounts to sign-in for commenting on web pages.

The Disqus widget is loaded asynchronously meaning it downloads the JavaScript in parallel and would not therefore impact the load time of your web pages. That said, the widget still adds lot of weight to your pages as the Disqus files will download on the user’s computer even if they aren’t interested in participating in the discussion. The other issue with auto-loading Disqus is that it makes your pages lengthy especially when viewed on mobile devices.

Load Disqus on Demand with JavaScript

As an alternative, you can configure Disqus on your website to load on-demand and not automatically. When someone clicks a button – like the example here – the widget will be dynamically added to your web page and not otherwise. This lazy-loading technique can be implemented in pure JavaScript without jQuery.

Step 1: Go to your web page template that has Disqus and replace the #disqus_thread <div> with the following snippet:

The page will have a “Show Comments” button and the comments are only loaded when the button is clicked.

Some websites have auto-loading enabled for Disqus but the widget is loaded when the reader has scrolled to the bottom of the article. This can again be done in JavaScript. We can use the onscroll method to check whenever the page is scrolled and if the user is near the bottom, the script will load the Disqus widget.

Amit Agarwal is a web geek and founder of Digital Inspiration, a popular tech & how-to website. He has been blogging for over a decade and has also contributed to the Wall Street Journal, Lifehacker and The Financial Express. Sign-up for the email newsletter for your daily dose of tips & tutorials.