I'm not an expert Drupal and PHP.. I would like to add a js file asynchronous but i don't know how. Now when I add a js file to my Drupal website (7.x) i use
drupal_add_js(path_to_theme() . '/scripts/Home.js');
but now i would like to add a js file asynchronous. Maybe i should to add
async => TRUE
but i don't know where....
So please can you help me and show how rewrite drupal_add_js ?
I hope you can help me, thanks a lot and sorry for my english.
If you want to add an external javascript to your head you can use drupal_add_html_head like this
$element = [
'#tag' => 'script',
'#value' => '',
'#attributes' => [
'src' => 'https://www.example.com/example.js',
'type' => 'application/javascript',
'async' => "async",
],
];
drupal_add_html_head($element, 'my_async_js');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With