Defer Disqus Plugin Loading

The Disqus for WordPress plugin lets site owners easily add Disqus to their sites, replacing the default WordPress comment system. Disqus is used by more than 2.5 million websites around the world, making it one of the most popular and widely used comment systems available.

Website performance is important, you don’t want your commenting system to slow you down. To measure the exact impact of the comment system is hard, as it can be affected by the number of comments and their content.

On each page view, Disqus loads multiple javascript files. There is no need to load all of those resources on every page. Ideally Disqus should only load when it’s required.

Conditional Load

Add the following line to your functions.php file.

/** Load on posts only */
function filter_dsq_can_load( $script_name ) {
	if ( !is_single() && ( 'count' === $script_name || 'embed' === $script_name )) {
		return false;
	}
	return true;
}
add_filter( 'dsq_can_load', 'filter_dsq_can_load' );

Summary

You’ll have better loading speed for your pages plus the awesome standard Disqus comments you love for your posts!

Do you use Disqus on your website?  What is your opinion of Disqus?  Please let us know your views.