passive event listener
An event listener registered with { passive: true }, which promises never to call preventDefault, so the browser can scroll immediately without waiting for it.
In more detail
For touch and wheel events the browser must normally wait to see whether the listener cancels the scroll. A passive listener removes that wait; calling preventDefault inside one is ignored and logs a warning. Browsers make touch and wheel listeners on window, document and body passive by default.
Example
el.addEventListener('touchstart', onTouch, { passive: true })Related terms
- event listener — A function registered with addEventListener that the browser calls whenever a given event happens on an element or on window.
- preventDefault — A method on an event that cancels the browser's built-in action, such as submitting a form or following a link.
- compositor thread — A browser thread, separate from the main thread, that combines layers into frames and can scroll and run some animations on its own.
- jank — Visible stutter or freezing in scrolling or animation, caused when the browser misses frames because work took too long.
- touch-action — The CSS property that tells the browser in advance which touch gestures it should handle itself, such as vertical panning, and which to leave to your code.
Taught in
- Passive Listeners, Scroll Performance And Touch Interactions — Frontend Architecture & Web Platform