Skip to content

Instantly share code, notes, and snippets.

@JudeRosario
Last active August 29, 2015 14:14
Show Gist options
  • Save JudeRosario/9ab1e43114adf17224c0 to your computer and use it in GitHub Desktop.
Save JudeRosario/9ab1e43114adf17224c0 to your computer and use it in GitHub Desktop.
JS Foo to force Async Loading
add_filter( 'script_loader_tag', function ( $tag, $handle ) {
return preg_replace("/(><\/[a-zA-Z][^0-9](.*)>)$/", " async $1 ", $tag );
}, 10, 2 );
@JudeRosario
Copy link
Author

This snippet loads all WordPress site JS in an async way, speeding up site loads. Simply copy paste in a child theme's functions.php or a site specific plugin.

@JudeRosario
Copy link
Author

Also you can add logic to this and filter selectively based on the $handle. This lets you load only the bare minimum before DOM is ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment