woocommerce / FlexSlider

An awesome, fully responsive jQuery slider plugin
http://www.woocommerce.com/flexslider/
GNU General Public License v2.0
4.91k stars 1.69k forks source link

Does not use Passive Event Listeners to Improve Scrolling Performance #1719

Closed blink1217 closed 2 months ago

blink1217 commented 6 years ago

Add the passive flag to all of the event listeners that Lighthouse has identified. In general, add the passive flag to every wheel, mousewheel, touchstart, and touchmove event listener that does not call preventDefault().

In browsers that support passive event listeners, marking a listener as passive is as easy as setting a flag:

document.addEventListener('touchstart', onTouchStart, {passive: true}); However, in browsers that do not support passive event listeners, the third parameter is a boolean to indicate whether the event should bubble or capture. So, using the syntax above may cause unintended consequences.

// Test via a getter in the options object to see if the passive property is accessed var supportsPassive = false; try { var opts = Object.defineProperty({}, 'passive', { get: function() { supportsPassive = true; } }); window.addEventListener("testPassive", null, opts); window.removeEventListener("testPassive", null, opts); } catch (e) {}

// Use our detect's results. passive applied if supported, capture will be false either way. elem.addEventListener('touchstart', fn, supportsPassive ? { passive: true } : false); To make this simpler you can use the feature detect from Detect It, eg:

elem.addEventListener('touchstart', fn, detectIt.passiveEvents ? {passive:true} : false);

JacobDB commented 5 years ago

Just to add to this – if you do indeed need to use preventDefault() within a eventListener, you can explicitly set { passive: false } to suppress the Lighthouse warning.

ndvbd commented 3 years ago

Any update here? Doing what @blink1217 suggested does not "kill"/"disable" the preventDefault which is found in the .js code?