• Hi,

    loading times become more important every day. Therefore I’d like to load the jQuery.js in the header with an “async”-tag. The registration of the jQuery is done by wp-include/script-loader.php:

    // jQuery
    	$scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '1.10.2' );
    	$scripts->add( 'jquery-core', '/wp-includes/js/jquery/jquery.js', array(), '1.10.2' );

    Now, I am not so skilled in writing php, and I don’t know where and how to tell the script to load jQuery with “async”. Any hints for me?

    Cheers,
    Stefan

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The actual output can come from many sources, depending on a number of parameters. Most of these would be difficult alter what is output. Here’s one thing to try, it may work for your situation… or not. If it doesn’t, you may need to give up on the idea.

    Hook the filter ‘print_head_scripts’ and declare global $wp_scripts;. Check the value of $wp_scripts->print_html. If it contains a string of script tags, use str_replace() to insert the asynch attribute where needed. Regardless if anything is done or not, return true.

    Note this filter fires for any head section scripts that may be enqueued. You need to check the src attributes if you only want to apply asynch to jQuery.

Viewing 1 replies (of 1 total)
  • The topic ‘Add "async" by script-loader.php’ is closed to new replies.