How to add defer / async in wp_enqueue_script

script_loader_tag

To add defer / async to enqueued script with id “fontawesome5

<?php
wp_enqueue_script('fontawesome5', 'https://use.fontawesome.com/releases/v5.0.9/js/all.js', array(), '5.0.9', true);
<?php
add_filter('script_loader_tag', 'add_defer', 10, 2);

function add_defer($tag, $handle) {
  if($handle !== 'fontawesome5') {
    return $tag;
  }
  
  return str_replace(' src=', ' defer src=', $tag);
}
<?php
add_filter('script_loader_tag', 'add_async', 10, 2);

function add_async($tag, $handle) {
  if($handle !== 'fontawesome5') {
    return $tag;
  }
  
  return str_replace(' src=', ' async src=', $tag);
}

Source: https://e-joint.jp/505/