Title: Add &quot;async&quot; by script-loader.php
Last modified: August 21, 2016

---

# Add "async" by script-loader.php

 *  [Farlif](https://wordpress.org/support/users/farlif/)
 * (@farlif)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/add-async-by-script-loaderphp/)
 * 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](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/add-async-by-script-loaderphp/#post-4034285)
 * 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.

## Tags

 * [async](https://wordpress.org/support/topic-tag/async/)
 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [Loading Times](https://wordpress.org/support/topic-tag/loading-times/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/add-async-by-script-loaderphp/#post-4034285)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
