Please can any one tell me what's the difference between:

  • adding a java script to a webform using js injector module
  • adding it using Implements hook_form_alter() and $form['#attached']['js']

2 Answers 2


Technically the difference is very small.

Whatever js you add in $form['#attached']['js'] is added via drupal_add_js() when the form attachments are processed using drupal_process_attached() - just like the JS Injector Module adds js snippets using drupal_add_js().

The JS Injector page claims the js it serves is loaded last, so order is an aspect where the two approaches may differ, unless you do some manual adjusting of the loading order afterwards.

If you try to decide what to use - it really depends. If it is just a minor snippet you want to add, the injector has the advantage that you don't need to write an entire custom module just to add some minor js functionality. It might also be nice for front end designers who know js, but have little experience with php or writing modules. If the js to add is part of a larger module/functionality upgrade anyway though, there is little reason to make use of the JS Inspector Module.


The most important difference is all JavaScript code in js_injector module will only exists in Database, which cannot be managed by version control software. It can be a disaster.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.