WordPress / plugin-check

A repository for the new Plugin Check plugin from the WordPress Performance and Plugins Team.
https://wordpress.org/plugins/plugin-check/
GNU General Public License v2.0
195 stars 39 forks source link

`Non_Blocking_Scripts_Check`: Warn about enqueued scripts that use neither `defer` nor `async` #467

Open adamsilverstein opened 3 weeks ago

adamsilverstein commented 3 weeks ago

As proposed by @felixarntz in https://github.com/WordPress/plugin-check/issues/443, this check would help encourage user to switch to non blocking enqueues.

Potentially we could also accept a blocking script as long as it's $in_footer. But it would definitely warn about a blocking in head script.

@swissspidy pointed out that The corresponding PHPCS sniff does not yet support the new $args param we added in 6.3. It was also indicated that the sniff might actually be removed because it's harder to detect. So probably needs to be a runtime check.

swissspidy commented 6 hours ago

We can probably use Enqueued_Scripts_Size_Check as a base and then simply check $script->extra['strategy'] of all the enqueued scripts.

Related:

We might want to have an abstract class for shared logic to reduce repetition.