My blog is a static website generated using Hugo and running on Netlify (you can read about my move from WordPress to Hugo in a previous article) but I still want to allow users to leave comments on my posts so I use Disqus like many other blogs.
Most of my blog posts do not have any comments so making about 50 unnecessary requests seems like a lot of waste. I noticed that many other websites do not load comments immediately but load them on demand. This way the wasteful requests are made only when really needed, when someone wants to read the comments or post a new one.
disqus-comment-count on the website and fetch the comments count for their
data-disqus-url attribute. The resulting “Show comments” button may then look like this
And that is it. If you want to see it in action, just click the button below near the end of this page. If you want to see it all integrated, just look at the source code of this page.