Skip to content

Commit

Permalink
add async and defer check in dependent check
Browse files Browse the repository at this point in the history
  • Loading branch information
kt-12 committed Feb 28, 2023
1 parent f746dfd commit f20cfea
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/wp-includes/class-wp-scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,8 @@ private function all_dependents_are_deferrable( $handle, $checked = array() ) {

// Consider each dependent and check if it is deferrable.
foreach ( $dependents as $dependent ) {
// If the dependent script is not using the defer strategy, no script in the chain is deferrable.
if ( 'defer' !== $this->get_intended_strategy( $dependent ) ) {
// If the dependent script is not using the defer or async strategy, no script in the chain is deferrable.
if ( ! in_array( $this->get_intended_strategy( $dependent ), array( 'defer', 'async' ), true ) ) {
return false;
}

Expand All @@ -828,16 +828,18 @@ private function all_dependents_are_deferrable( $handle, $checked = array() ) {
* @return string $strategy return the final strategy.
*/
private function get_eligible_loading_strategy( $handle = '' ) {
if ( ! isset( $this->registered[ $handle ] ) ) {
return '';
}

$intended_strategy = $this->get_intended_strategy( $handle );
/*
* Handle known blocking strategy scenarios.
*
* blocking if not a registered handle.
* blocking if explicitly set.
* blocking if script args not set.
* blocking if explicitly set.
*/
if ( ! isset( $this->registered[ $handle ] ) || 'blocking' === $intended_strategy || ! $intended_strategy ) {
if ( ! $intended_strategy || 'blocking' === $intended_strategy ) {
return '';
}

Expand All @@ -846,7 +848,7 @@ private function get_eligible_loading_strategy( $handle = '' ) {
return 'async';
}

// Handling defer strategy scenarios. Dependency will never be set async. So only checking dependent.
// Handling defer strategy scenarios.
if ( $this->all_dependents_are_deferrable( $handle ) ) {
return 'defer';
}
Expand Down

0 comments on commit f20cfea

Please sign in to comment.