Try to load details library only when details element is present

Created on 19 October 2025, 9 days ago
Updated 23 October 2025, 5 days ago

Problem/Motivation

The following three libraries are loaded for even a very simple webform. In the case I found it was the front page of Byte which is the new Drupal CMS site template.


webform.element.details.save:
  js:
    js/webform.element.details.save.js: {}
  dependencies:
    - core/drupal
    - core/jquery
    - core/once
  
webform.element.details.toggle:
  css:
    component:
      css/webform.element.details.toggle.css: {}
  js:
    js/webform.element.details.toggle.js: {}
  dependencies:
    - core/drupal
    - core/drupal.announce
    - core/jquery
    - core/once

Because the libraries depend on jQuery, this means that an anonymous front page request on Byte is loading jQuery - however the form itself is an e-mail field and a submit button - it seems likely the JavaScript isn't actually used at all in this context. So if it's possible to avoid loading those libraries, it would allow over 70+kb of js to be saved from Drupal CMS's default recipe's front page.

Steps to reproduce

Proposed resolution

Looks like at least one place resulting in this is:

hook_form_alter()

    // Add details 'toggle all' to all webforms (except submission forms).
    if (!$form_object instanceof WebformSubmissionForm) {
      $form['#attributes']['class'][] = 'js-webform-details-toggle';
      $form['#attributes']['class'][] = 'webform-details-toggle';
      $form['#attached']['library'][] = 'webform/webform.element.details.toggle';
      return;
    }

There doesn't seem to be a way to prevent this library being added at all.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

6.3

Component

Code

Created by

🇬🇧United Kingdom catch

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024