Add custom attribute to an external JS script
I solved the problem using drupal_add_html like this,

$data = array(
  '#tag' =&gt; 'script',
  '#value' =&gt; '',
  '#attributes' =&gt; array(
    'src' =&gt; 'https://code.jquery.com/jquery-3.4.1.js',
    'integrity' =&gt; 'sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=',
  ),
);
drupal_add_html_head($data, 'unique_key');