Adding JavaScript and CSS to every page in Drupal without using hook_init()

pere · 16th February, 2014

The problem of adding css or javascript inside a hook_init() implementation, is that the hook is called during _drupal_bootstrap_full(), and will run in cases where we are not delivering HTML (such as AJAX requests). Even if this does not have any visible effect, as the html is never outputted in these requests, it unnecessarily penalises them.