[Resolved] How would I fix this?

Home Forums Support How would I fix this?

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1487752
    Het

    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’);

    #1488189
    David
    Staff
    Customer Support

    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.

    #1610431
    Charbel

    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

    #1610462
    Elvin
    Staff
    Customer Support

    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 } );

    A wise man once said:
    "Have you cleared your cache?"

    #1610466
    Charbel

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

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

    #1610468
    Elvin
    Staff
    Customer Support

    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. πŸ™‚

    A wise man once said:
    "Have you cleared your cache?"

    #1610472
    Charbel

    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!!!

    #1610483
    Elvin
    Staff
    Customer Support

    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. πŸ˜€

    A wise man once said:
    "Have you cleared your cache?"

    #1610528
    Charbel

    Thank you @Elvin,

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

    All the best,

    #1610534
    Elvin
    Staff
    Customer Support

    No problem. πŸ™‚

    A wise man once said:
    "Have you cleared your cache?"

    #1614803
    linuxwolf

    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.

    #1615192
    Elvin
    Staff
    Customer Support

    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. πŸ˜€

    A wise man once said:
    "Have you cleared your cache?"

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.