Site logo

Archived topic

How would I fix this?

17 replies · Started by Het on October 13, 2020

Viewing posts 1–15 of 18

So I did a test with no comments Vs having a comment. I use this comment as a SHORTCode via using a child theme. With no comments I don't get this in google page insights:

Does not use passive listeners to improve scrolling performance
Consider marking your touch and wheel event listeners as passive to improve your page's scroll performance. Learn more.
URL
Location
../wp-includes/js/comment-reply.min.jsjs/comment-reply.min.js(cdn.statically.io)
line: 1

Yes I am using statically CDN.

Here is list of code from my CHild theme.
Here is my code for my comments (comments.php:
https://hasteb.in/tubewofa.js
Here is code for my single post (Single.php):
https://hasteb.in/nocotovo.js
Here is my functions.php (theme functions) for which has the shortcode thing for comments:
function display_comment_list() {
ob_start();
global $post;
//print_r($meta);
?>
<?php get_comments();
comments_template();?>

<?php return ob_get_clean();
}
add_shortcode('comment-list', 'display_comment_list');

Hi there,

this is a known WordPress 'bug' - it is not something that the Theme can fix. Here is one of the more recent CoreTracs raised on the issue:

https://core.trac.wordpress.org/ticket/47510

As you can see a proposed solution has yet to be implemented.

There was one fix found here:

https://stackoverflow.com/a/45974787

But please note the comments as this fix may interfere with other scripts.

Thank you @David,

Could you please advise how to implement the fix noted on Stackoverflow here? https://stackoverflow.com/a/45974787

I am running GeneratePress with Dispatch Theme. I have a staging site and willing to try it.

Many Thanks!
-Charbel

Hi,

If its about adding the script provided, you can add it in using Code Snippets plugin.
https://wordpress.org/plugins/code-snippets/

Add new snippet and place this code in:

add_action( 'wp_footer', function () { ?>
<script>
(function() {
  var supportsPassive = eventListenerOptionsSupported();  

  if (supportsPassive) {
    var addEvent = EventTarget.prototype.addEventListener;
    overwriteAddEvent(addEvent);
  }

  function overwriteAddEvent(superMethod) {
    var defaultOptions = {
      passive: true,
      capture: false
    };

    EventTarget.prototype.addEventListener = function(type, listener, options) {
      var usesListenerOptions = typeof options === 'object';
      var useCapture = usesListenerOptions ? options.capture : options;

      options = usesListenerOptions ? options : {};
      options.passive = options.passive !== undefined ? options.passive : defaultOptions.passive;
      options.capture = useCapture !== undefined ? useCapture : defaultOptions.capture;

      superMethod.call(this, type, listener, options);
    };
  }

  function eventListenerOptionsSupported() {
    var supported = false;
    try {
      var opts = Object.defineProperty({}, 'passive', {
        get: function() {
          supported = true;
        }
      });
      window.addEventListener("test", null, opts);
    } catch (e) {}

    return supported;
  }
})();
</script>
<?php } );

Thank you @Elvin, much appreciated for your quick response.

Can I add the code above directly to my function.php Child Theme instead?

Can I add the code above directly to my function.php Child Theme instead?

Ah sure you can do that too if you don't want to use the plugin. :)

Thank you so much @Elvin!!!

I used your code and paste it directly in my function.php.
Finally, the warning is gone now from Google PageSpeed Insights :)

Yesterday, I tried the code noted on Stackoverflow https://stackoverflow.com/a/45974787, however, I got an error when Updating my function.php, it could be a Syntax error.

Many Thanks!!!

Perhaps you forgot to place it inside a wp_footer hook.

This add_action( 'wp_footer', ... ); line is pretty important.

No problem. Glad to be of any help. :D

Thank you @Elvin,

Yes, the add_action( 'wp_footer', ... ); was missing from Stackoverflow example.

All the best,

No problem. :)

Hi Elvin,

Thank you so much. I have used the code directly with the code snippet by pressing the "Add new" button. It is working, although many things to improve.

Thank you so much. I have used the code directly with the code snippet by pressing the “Add new” button. It is working, although many things to improve.

Nice one. Glad you're figuring things out. No problem. :D

Hi Elvin,
If I can ask directly...I used the above snippet in functions.php.
It did the job, except after adding it, Lightbox plugin stopped working.
Could something be changed within the code that it will not affect Lightbox plugin?
thanks,
Tibor
https://surf-atlantic.com/photo-gallery/

Hi there,

Just checked the page and lightbox gallery is working for me?

Hi Leo,
I put that snippet back to functions.php now.
Lightbox Gallery is not working, Any easy fix within the code?
thanks

This archived topic is closed to new replies.