Is passive: true
necessary in scroll listeners?
#2023
-
Hello there, this is the page in question: https://www.30secondsofcode.org/js/s/passive-scroll-listener-performance/ According to the specifications, adding passive: true to scroll is not necessary: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
@rebelmusic Hi there! Thank you for raising this issue. The use of |
Beta Was this translation helpful? Give feedback.
-
@Grenish is actually correct in his answer. Thanks everyone for your patience. |
Beta Was this translation helpful? Give feedback.
@rebelmusic Hi there! Thank you for raising this issue. The use of
{ passive: true }
in a scroll event listener is related to optimizing browser performance. It indicates that the listener won't prevent default scrolling behavior.If your code inside the listener doesn't include actions that prevent default behavior, like
event.preventDefault()
, thenusing { passive: true }
might be unnecessary. Browsers may interpret it differently, and testing in your specific context will help decide if it's beneficial.