I've tried:
drupal_add_js('http://somesite.com/pages/scripts/0080/8579.js', [
'type' => 'external',
'async' => TRUE
]);
and
drupal_add_js('http://somesite.com/pages/scripts/0080/8579.js', [
'type' => 'external',
'async' => 'async'
]);
With no results.
Would any know how I could achieve this?
You can't achieve this just by specifying the option because
drupal_add_js()
does not supportasync
attribute.It is recommended to use
defer
which is (imho) better because it doesn't block HTML parsing.async
: script fetched asynchronously, then HTML parsing is paused to execute the script, then parsing resumes.defer
: script fetched asynchronously and executed only after HTML parsing is done.However, if you really need the
async
attribute, you can implement thehook_preprocess_html_tag
to alter the theme variables, like so :