Benefits
- Improves rendering speed
Add this into functions.php file
add_filter('script_loader_tag', function ($tag, $handle) {
$async_scripts = [
'my-script'
];
if (in_array($handle, $async_scripts)) {
return str_replace(' src', ' async src', $tag);
}
return $tag;
}, 10, 2);