Search code examples
phpasynchronousdrupaldrupal-7

async => TRUE in drupal_add_js() : asynchronous call for a js file


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.


Solution

  • You could do that with the "Asynchronous JavaScript" module for Drupal 7 at : https://www.drupal.org/project/async_js

    Or you could implement hook_js_alter() and add in the async = TRUE key to the external file. Check this link on Drupal: https://www.drupal.org/node/2299773