Add custom attribute to an external JS script It's not really clear how to add custom attributes when adding an external JS script to the page.

Currently I have this code:

drupal_add_js('https://code.jquery.com/jquery-3.4.1.js', array('type' =&gt; 'external'));


How can I add an integrity attribute to the rendered script tag?

The rendered script should look like this:

&lt;script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="&gt;&lt;/script&gt;


I know this post exists, but I'm not able to use that solution since the source is loaded externally and I will not be able to check on the source.
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');