Ticket #12009: defer and async.patch
File defer and async.patch, 2.5 KB (added by , 13 years ago) |
---|
-
class.wp-scripts.php
114 114 115 115 $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) ); 116 116 117 $defer = isset($this->registered[$handle]->extra['defer'])?"defer='defer'":false; 118 $async = isset($this->registered[$handle]->extra['async'])?"async='async'":false; 119 117 120 if ( $this->do_concat ) 118 $this->print_html .= "<script type='text/javascript' src='$src' ></script>\n";121 $this->print_html .= "<script type='text/javascript' src='$src' $defer $async ></script>\n"; 119 122 else 120 echo "<script type='text/javascript' src='$src' ></script>\n";123 echo "<script type='text/javascript' src='$src' $defer $async ></script>\n"; 121 124 122 125 return true; 123 126 } -
functions.wp-scripts.php
49 49 * @param bool $in_footer (optional) Whether to enqueue the script before </head> or before </body> 50 50 * @return null 51 51 */ 52 function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {52 function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false, $defer = false, $async = false ) { 53 53 global $wp_scripts; 54 54 if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { 55 55 if ( ! did_action( 'init' ) ) … … 61 61 $wp_scripts->add( $handle, $src, $deps, $ver ); 62 62 if ( $in_footer ) 63 63 $wp_scripts->add_data( $handle, 'group', 1 ); 64 if ( $async ) 65 $wp_scripts->add_data( $handle, 'async', 1 ); 66 if ( $defer ) 67 $wp_scripts->add_data( $handle, 'defer', 1 ); 68 64 69 } 65 70 66 71 /** … … 122 127 * @since r16 123 128 * @see wp_register_script() For parameter information. 124 129 */ 125 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) {130 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false, $defer = false, $async = false ) { 126 131 global $wp_scripts; 127 132 if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { 128 133 if ( ! did_action( 'init' ) ) … … 136 141 $wp_scripts->add( $_handle[0], $src, $deps, $ver ); 137 142 if ( $in_footer ) 138 143 $wp_scripts->add_data( $_handle[0], 'group', 1 ); 144 if ( $async ) 145 $wp_scripts->add_data( $handle, 'async', 1 ); 146 if ( $defer ) 147 $wp_scripts->add_data( $handle, 'defer', 1 ); 148 139 149 } 140 150 $wp_scripts->enqueue( $handle ); 141 151 }