Disqus update

Post Reply
kosi77
Sr. Bludit
Posts: 33
Joined: Wed Jan 30, 2019 7:23 am

When you turn on the disqus application, the page views in PageSpeed Insights are very slow.

What did I do to make the indicators very good!
I changed the plugin code a bit as follows:

Open the plugin.php file and find:

Code: Select all

$code = <<<EOF
<!-- Disqus plugin -->
<div id="disqus_thread"></div>
<script>

	var disqus_config = function () {
		this.page.url = '$pageURL';
		this.page.identifier = '$pageID';
	};

	(function() { // DON'T EDIT BELOW THIS LINE
		var d = document, s = d.createElement('script');
		s.src = 'https://$shortname.disqus.com/embed.js';
		s.setAttribute('data-timestamp', +new Date());
		(d.head || d.body).appendChild(s);
	})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<!-- /Disqus plugin -->
EOF;
		return $code;
Replace with:

Code: Select all

$code = <<<EOF
<!-- Disqus plugin -->
<div id="disqus_thread"></div>
<script>

	var disqus_config = function () {
	this.page.url = '$pageURL';
	this.page.identifier = '$pageID';
};

var disqus_observer = new IntersectionObserver(function(entries) {
    // comments section reached
    // start loading Disqus now
    if(entries[0].isIntersecting) {
        (function() {
            var d = document, s = d.createElement('script');
            s.src = 'https://$shortname.disqus.com/embed.js';
            s.setAttribute('data-timestamp', +new Date());
            (d.head || d.body).appendChild(s);
        })();

        // once executed, stop observing
        disqus_observer.disconnect();
    }
}, { threshold: [0] });
disqus_observer.observe(document.querySelector("#disqus_thread"));
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<!-- /Disqus plugin -->
EOF;
		return $code;
That is, now the disqus is shown only after you scroll to the end of the page.

I hope I was helpful!
kosi77
Sr. Bludit
Posts: 33
Joined: Wed Jan 30, 2019 7:23 am

How does this modified code work?

See the site in my signature!
Post Reply