wp-media / wp-rocket

Performance optimization plugin for WordPress
https://wp-rocket.me
GNU General Public License v2.0
687 stars 215 forks source link

Delay JS execution time (LazyLoad Script) - V2 #3738

Closed Tabrisrp closed 3 years ago

Tabrisrp commented 3 years ago

What are we proposing to do?

To build a new way to delay the execution of JavaScript and getting a significant boost on website performance. WP Rocket will delay all JavaScript instead of an inclusion list with the current feature.

Why are we doing this?

With the new Core Web Vitals metrics, the goal for performance tools is to provide the best user experience to deliver as fast as possible content above the fold. To do this, we need to load the images when needed (Lazyload), to avoid render-blocking files (defer JavaScript and defer non-critical CSS), preload critical assets, etc...

Most websites are loading a ton of JavaScript used for non-critical features. With this feature, WP Rocket will preload and delay all JavaScript by respecting the loading order.

As a side effect, it will improve PageSpeed score and loading time.

Full feature doc

gevcen commented 3 years ago

When reading the phrase "we need to load the images when needed (Lazyload)", does that relate to the issue reported in the ticket https://github.com/wp-media/wp-rocket/issues/3695? Thanks

piotrbak commented 3 years ago

@Tabrisrp This LL script should be also excluded: https://github.com/wp-media/rocket-lazyload-common/blob/bca56461c1126f4e2b7cc567ac457df69700dc38/src/Assets.php#L237

piotrbak commented 3 years ago

@Tabrisrp @GeekPress I'm also thinking, should we delay our Critical CSS script? 🤔

GeekPress commented 3 years ago

@piotrbak It shouldn't cause any problem.

cgold1979 commented 3 years ago

The new delay javascript is causing an issue with website monetization as it delays the execution of external header bidding partners lowering viewability and the time it takes to show ads on the site. This will impact many publishers' revenues without them even knowing.

Snadex commented 3 years ago

The new update and most probably this feature prevented hubspot forms to load. They were working just fine before.

gamersdunia16 commented 3 years ago

want to exclude google ads from Delay JavaScript. I tried by adding two keywords adsbygoogle.js and pagead2.googlesyndication.com to the exclusion list but it did not work. any suggestion!!

GeekPress commented 3 years ago

@gamersdunia16 Please open a ticket support from here: https://wp-rocket.me/support/

We won't provide you help on Github, it's not the right place.