|
@@ 255-273 (lines=19) @@
|
| 252 |
|
return $tag; |
| 253 |
|
} |
| 254 |
|
|
| 255 |
|
private function should_async_script( $script ) { |
| 256 |
|
global $wp_scripts; |
| 257 |
|
|
| 258 |
|
// explicitly in the header (scripts aren't affected much by async) |
| 259 |
|
$should_async_script = $script->args === 0; |
| 260 |
|
|
| 261 |
|
// only make scripts async if nothing depends on them |
| 262 |
|
foreach ( $wp_scripts->to_do as $other_script_handle ) { |
| 263 |
|
$other_script = $wp_scripts->registered[ $other_script_handle ]; |
| 264 |
|
if ( in_array( $script->handle, $other_script->deps ) ) { |
| 265 |
|
$should_async_script = false; |
| 266 |
|
break; |
| 267 |
|
} |
| 268 |
|
} |
| 269 |
|
|
| 270 |
|
// you can override this logic by setting jetpack-async |
| 271 |
|
$should_async_script = $should_async_script || ( isset( $script->extra['jetpack-async'] ) && $script->extra['jetpack-async'] ); |
| 272 |
|
return $this->async_scripts && apply_filters( 'jetpack_perf_async_script', $should_async_script, $script->handle, $script->src ); |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
private function should_defer_script( $script ) { |
| 276 |
|
global $wp_scripts; |
|
@@ 275-292 (lines=18) @@
|
| 272 |
|
return $this->async_scripts && apply_filters( 'jetpack_perf_async_script', $should_async_script, $script->handle, $script->src ); |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
private function should_defer_script( $script ) { |
| 276 |
|
global $wp_scripts; |
| 277 |
|
|
| 278 |
|
// if it's explicitly not in the footer, or we have Jetpack Defer set, and has no dependencies |
| 279 |
|
$should_defer_script = $script->args === 0; |
| 280 |
|
|
| 281 |
|
// only make scripts deferred if nothing depends on them |
| 282 |
|
foreach ( $wp_scripts->to_do as $other_script_handle ) { |
| 283 |
|
$other_script = $wp_scripts->registered[ $other_script_handle ]; |
| 284 |
|
if ( in_array( $script->handle, $other_script->deps ) ) { |
| 285 |
|
$should_defer_script = false; |
| 286 |
|
break; |
| 287 |
|
} |
| 288 |
|
} |
| 289 |
|
|
| 290 |
|
$should_defer_script = $should_defer_script || ( isset( $script->extra['jetpack-defer'] ) && $script->extra['jetpack-defer'] ); |
| 291 |
|
return $this->defer_scripts && apply_filters( 'jetpack_perf_defer_script', $should_defer_script, $script->handle, $script->src ); |
| 292 |
|
} |
| 293 |
|
|
| 294 |
|
private function should_remove_script( $script ) { |
| 295 |
|
return $this->should_remove_asset( 'jetpack_perf_remove_script', $script ); |