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

user12945822 picture user12945822 · Feb 22, 2020 · Viewed 20.3k times · Source

A recent Lighthouse Report flagged the following issue.

Does not use passive listeners to improve scrolling performance

It also mentions...

Consider marking your touch and wheel event listeners as passive to improve your page's scroll performance.

How do I resolve this issue? It appears to be related to jQuery.

Answer

Satelier Diego picture Satelier Diego · Jun 3, 2020

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

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