0

I have a node content type with comments enabled, and the "Add comment" form is configured to be displayed on each node page.

Embedding the add comment form causes JQuery and all its dependencies to get pulled in, but since the form works without Javascript, I want to improve performance by disabling form.js.

However, I haven't been able to figure out how to do this using the tools core provides.

The JS is getting loaded from the drupal.form library in core.libraries.yml:

drupal.form:
  version: VERSION
  js:
    misc/form.js: {}
  dependencies:
    - core/jquery
    - core/drupal
    - core/drupal.debounce
    - core/jquery.once

I looked at using hook_js_alter(), but that hook doesn't provide a way to get the form ID.

I also thought of using hook_form_alter(), but I couldn't find a way to modify the JS there, either.

1
  • You can remove the library from $form['#attached']['library'] in a form alter hook. But this is a bit more complex, because there is a second dependency on this library comment/drupal.comment which is used in more places, for example in the field widget for which you need a different alter hook. And the question is, after removing all the dependencies, does the comment form still work? – 4k4 Dec 16 '20 at 9:57

Your Answer

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

Browse other questions tagged or ask your own question.