1

I am trying to place all javascript in external files, is it possible to place Drupal.settings javascript in an external file? It is displayed like:

jQuery.extend(Drupal.settings, { "basePath": "/", "fbconnect": { "user_pictures": "allow", "language_code": "en_US",...

3 Answers 3

2

This is not possible without hacking the core. This javascript is assembled and injected into the page in includes/common.inc (check line 4312 in the api reference).

3

Yes - this won't make a difference to Drupal where the file is coming from. In Drupal, you can load this using drupal_add_js:

drupal_add_js('http://example.com/example.js', 'external');

Note that these files will not get aggregated when preprocessing is on.

The other thing to watch for with external javascript is to make sure you are testing for the existence of functions / variables if you are calling them in your file since you can't control the order / speed that they are loading in.

2
  • How does this address getting Drupal.settings into an external file?
    – mpdonadio
    Mar 10, 2013 at 20:43
  • What am I missing - OP asked whether Drupal.settings JS can be placed in external files not passing variables to an external file.
    – schnippy
    Mar 11, 2013 at 4:28
2

It is considered bad practice to have big inline javascripts. A lot of Drupal modules add settings to the Drupal.settings object. This means that we can end up with an enourmous inline script.

I think a solution should be found to allow Drupal.settings to be put in an external file rather than using inline

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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