Last active
August 29, 2015 14:14
-
-
Save JudeRosario/9ab1e43114adf17224c0 to your computer and use it in GitHub Desktop.
JS Foo to force Async Loading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'script_loader_tag', function ( $tag, $handle ) { | |
return preg_replace("/(><\/[a-zA-Z][^0-9](.*)>)$/", " async $1 ", $tag ); | |
}, 10, 2 ); |
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
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.