simone960's picture

I wonder how to add an attribute "async" to the header with backdrop_add_js ?

Here is the script linked to external js file I want to output in the header:

<script async src="external-js-path"></script>

Here's my code but I'm stuck here:

backdrop_add_js("external-js-path", array('type' => 'external', 'scope' => 'header'));

 

 

Accepted answer

backdrop_add_js() takes two parameters: $data and $options. One of the keys you can add to the $options array is attributes:

An associative array of attributes for the <script> tag. This may be used to add 'async' or custom attributes.

See https://docs.backdropcms.org/api/backdrop/core%21includes%21common.inc/f... for full details.

Comments

simone960's picture

Thanks !  Here the code I guess.

backdrop_add_js('external-js-path', array(
      'type' => 'external',
      'scope' => 'header',
      'attributes' => array('async' => TRUE),
    ));