Jump to content

[SOLVED] Uses Passive Event Listeners to Improve Scrolling Performance (PS1.7.4.2)


DARKF3D3

Recommended Posts

Google recommend using Passive Event Listeners to Improve website Scrolling Performance:

https://developers.google.com/web/tools/lighthouse/audits/passive-event-listeners

In particular, regards of my website (using classic theme), it highlighted these lines:

/themes/core.js ----------------------------------------------------- line: 946
/content.js(dkpejdfnpdkhifgbancbammdijojoffk) -------- line: 42
/content.js(dkpejdfnpdkhifgbancbammdijojoffk) -------- line: 89
/content.js(dkpejdfnpdkhifgbancbammdijojoffk) -------- line: 161

 

Do you know if it's safe to do this and how this can be done?

Edited by DARKF3D3 (see edit history)
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

  • 2 years later...
  • 1 month later...
  • 3 months later...

You mean adding place the code from /default-passive-events/dist/index.js into my theme custom.js file?

var e,t=["scroll","wheel","touchstart","touchmove","touchenter","touchend","touchleave","mouseout","mouseleave","mouseup","mousedown","mousemove","mouseenter","mousewheel","mouseover"];if(function(){var e=!1;try{var t=Object.defineProperty({},"passive",{get:function(){e=!0}});window.addEventListener("test",null,t),window.removeEventListener("test",null,t)}catch(e){}return e}()){var o=EventTarget.prototype.addEventListener;e=o,EventTarget.prototype.addEventListener=function(o,r,n){var s,a="object"==typeof n&&null!==n,i=a?n.capture:n;(n=a?function(e){var t=Object.getOwnPropertyDescriptor(e,"passive");return t&&!0!==t.writable&&void 0===t.set?Object.assign({},e):e}(n):{}).passive=void 0!==(s=n.passive)?s:-1!==t.indexOf(o)&&!0,n.capture=void 0!==i&&i,e.call(this,o,r,n)},EventTarget.prototype.addEventListener._original=e}
//# sourceMappingURL=index.js.map

 

Link to comment
Share on other sites

  • DARKF3D3 changed the title to [SOLVED] Uses Passive Event Listeners to Improve Scrolling Performance (PS1.7.4.2)
  • 1 year later...
  • 10 months later...
On 9/11/2021 at 6:03 PM, duredo said:

Thanks, this solution worked. For theme developers, you can simply create a file called anything (like passive-listener.js) inside your theme directory/_dev/assets/js/lib folder and paste the contents from the link above (https://unpkg.com/default-passive-events) and inside your theme/_dev/assets/js/theme.js file import it, that's it!

Many thanks to @duredo

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...