Proposal
Several CSS and JS libraries are currently loaded on every page regardless of whether they are needed. This impacts Core Web Vitals (LCP, CLS) for all sites using the theme.
The following assets are loaded unconditionally (acknowledged with @todo Include only if needed comments in dxpr_theme.theme):
- Bootstrap 5 override CSS (
dxpr_theme.theme:254) — loaded even when Bootstrap 5 components aren't on the page
- Enhanced dropdowns (
dxpr_theme.theme:261) — loaded even when no dropdown menus exist on the page
- Drupal Webform CSS (
dxpr_theme.theme:265) — loaded even when the Webform module is not installed
- DXPR Builder CSS (
dxpr_theme.theme:265) — loaded even when the Builder module is not installed
Proposed solution
Implement conditional #attached logic in dxpr_theme_preprocess_page() or hook_page_attachments_alter() to:
- Only attach webform CSS when the
webform module is installed (\Drupal::moduleHandler()->moduleExists('webform'))
- Only attach DXPR Builder CSS when
dxpr_builder module is installed
- Only attach enhanced-dropdowns library when a menu block with dropdowns is present on the page
- Evaluate whether Bootstrap 5 overrides can be scoped more narrowly
Expected impact
- Reduced CSS payload on pages that don't use these features
- Improved Lighthouse performance scores
- Better Core Web Vitals, particularly for content-heavy landing pages
Proposal
Several CSS and JS libraries are currently loaded on every page regardless of whether they are needed. This impacts Core Web Vitals (LCP, CLS) for all sites using the theme.
The following assets are loaded unconditionally (acknowledged with
@todo Include only if neededcomments indxpr_theme.theme):dxpr_theme.theme:254) — loaded even when Bootstrap 5 components aren't on the pagedxpr_theme.theme:261) — loaded even when no dropdown menus exist on the pagedxpr_theme.theme:265) — loaded even when the Webform module is not installeddxpr_theme.theme:265) — loaded even when the Builder module is not installedProposed solution
Implement conditional
#attachedlogic indxpr_theme_preprocess_page()orhook_page_attachments_alter()to:webformmodule is installed (\Drupal::moduleHandler()->moduleExists('webform'))dxpr_buildermodule is installedExpected impact