Does not use passive listeners to improve scrolling performance (Lighthouse Report) [closed]

There was a long thread on this topic in https://github.com/jquery/jquery/issues/2871 in 2016

In short:

  • jQuery can’t add support to passive listeners.
  • Is expected that this is added in jQuery 4 (4 years and still in 3.5.x)
  • The proposed fix is to add this code right after jQuery load:

jQuery.event.special.touchstart = {
        setup: function( _, ns, handle ){
            this.addEventListener("touchstart", handle, { passive: true });
        }
    };

UPDATE 2021: Add the following code after jquery. This will fix it and removes the Pagespeed warning

jQuery.event.special.touchstart = {
    setup: function( _, ns, handle ) {
        this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") });
    }
};
jQuery.event.special.touchmove = {
    setup: function( _, ns, handle ) {
        this.addEventListener("touchmove", handle, { passive: !ns.includes("noPreventDefault") });
    }
};
jQuery.event.special.wheel = {
    setup: function( _, ns, handle ){
        this.addEventListener("wheel", handle, { passive: true });
    }
};
jQuery.event.special.mousewheel = {
    setup: function( _, ns, handle ){
        this.addEventListener("mousewheel", handle, { passive: true });
    }
};

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)