Ticket #12009: async_defer_scripts_new.patch
File async_defer_scripts_new.patch, 3.4 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class.wp-scripts.php
276 276 $before_handle = $this->print_inline_script( $handle, 'before', false ); 277 277 $after_handle = $this->print_inline_script( $handle, 'after', false ); 278 278 279 echo '<pre>'; 280 print_r( $obj ); 281 echo '</pre>'; 282 279 283 if ( $before_handle ) { 280 284 $before_handle = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $before_handle ); 281 285 } … … 336 340 if ( ! empty( $ver ) ) 337 341 $src = add_query_arg( 'ver', $ver, $src ); 338 342 343 $async = isset( $obj->extra['async'] ) ? 'async' : ''; 344 $defer = isset( $obj->extra['defer'] ) ? 'defer' : ''; 345 339 346 /** This filter is documented in wp-includes/class.wp-scripts.php */ 340 347 $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) ); 341 348 … … 342 349 if ( ! $src ) 343 350 return true; 344 351 345 $tag = "{$cond_before}{$before_handle}<script type='text/javascript' src='$src' ></script>\n{$after_handle}{$cond_after}";352 $tag = "{$cond_before}{$before_handle}<script type='text/javascript' src='$src'{$async} {$defer}></script>\n{$after_handle}{$cond_after}"; 346 353 347 354 /** 348 355 * Filters the HTML script tag of an enqueued script. -
src/wp-includes/functions.wp-scripts.php
254 254 * If set to null, no version is added. 255 255 * @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>. 256 256 * Default 'false'. 257 * @param bool $async Optional. Adds the async tag to the script. 258 * @param bool $defer Optional. Adds the defer tag to the script. 257 259 */ 258 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) {260 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false, $async = false, $defer = false ) { 259 261 $wp_scripts = wp_scripts(); 260 262 261 263 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); … … 271 273 if ( $in_footer ) { 272 274 $wp_scripts->add_data( $_handle[0], 'group', 1 ); 273 275 } 276 277 if ( $async ) { 278 $wp_scripts->add_data( $_handle[0], 'async', 1 ); 279 } 280 281 if ( $defer ) { 282 $wp_scripts->add_data( $_handle[0], 'defer', 1 ); 283 } 274 284 } 275 285 276 286 $wp_scripts->enqueue( $handle ); -
src/wp-includes/script-loader.php
397 397 'ariaHide' => esc_attr__( 'Hide password' ), 398 398 ) ); 399 399 400 $scripts->add( 'setup-config', "/wp-admin/js/setup-config$suffix.js", array(), false, 1 ); 401 did_action( 'init' ) && $scripts->localize( 'setup-config', 'setupConfigL10n', array( 402 'show' => __( 'Show' ), 403 'hide' => __( 'Hide' ), 404 'ariaShow' => esc_attr__( 'Show password' ), 405 'ariaHide' => esc_attr__( 'Hide password' ), 406 ) ); 407 400 408 $scripts->add( 'language-chooser', "/wp-admin/js/language-chooser$suffix.js", array( 'jquery' ), false, 1 ); 401 409 402 410 $scripts->add( 'user-suggest', "/wp-admin/js/user-suggest$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );