2

I am trying to understand a bit more about where and how jQuery is loaded in Drupal 8.

If I write a custom script file that will include some translation strings using Drupal.t(), I need to add core/drupal as a dependency.

I know we have a call for jQuery: core/jquery, but hoping to have a clear understanding.

Drupal core in places uses jQuery, does calling core/drupal include jQuery? When using Drupal.t()?

Is there a difference when doing so inside a custom behaviors wrapper?

The premise is if I write my scripts in vanilla js, will using core/drupal and/or behaviors still call any jQuery?

1 Answer 1

1

No, core/drupal depends only from core/drupalSettings; using it will not load core/jquery. The definition of those libraries is contained in core.libraries.yml, where you can see their dependencies.

drupal:
  version: VERSION
  js:
    misc/drupal.js: { weight: -18 }
    misc/drupal.init.js: { weight: -17 }
  dependencies:
    - core/drupalSettings
  drupalSettings:
    suppressDeprecationErrors: true

drupalSettings:
  version: VERSION
  js:
    # Need to specify a negative weight like drupal.js until
    # https://www.drupal.org/node/1945262 is resolved.
    misc/drupalSettingsLoader.js: { weight: -18 }
  drupalSettings:
    # These placeholder values will be set by system_js_settings_alter().
    path:
      baseUrl: null
      scriptPath: null
      pathPrefix: null
      currentPath: null
      currentPathIsAdmin: null
      isFront: null
      currentLanguage: null
    pluralDelimiter: null

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.