The idea is the have: <script defer="defer" src="myscript.js> which will load in parallel.
Now PHP can so some work such as: return str_replace( ' src', ' defer="defer" src', $tag );
Now some scripts already have defer, so I was wondering, a duplicate should be OK but to be smart, should I not check first?
Not sure the best spot yet to install my idea, thoughts? Found this code on https://wordpress.stackexchange.com/que ... 8335#38335
Code: Select all
add_filter( 'script_loader_tag', function ( $tag, $handle ) {
if ( 'contact-form-7' !== $handle )
return $tag;
return str_replace( ' src', ' defer="defer" src', $tag );
}, 10, 2 );