Drupal.behaviors.myTheme =
attach: function (context, settings)
$('.button', context).on('click', function() ... );
;
Problems: jQuery dependency, global namespace pollution, difficult to test.
Instead of loading all CSS/JS globally, attach libraries only to the specific components rendered on the page. Drupal 10’s lazy-loading ensures that if a card component isn't on the page, its CSS isn't downloaded. modernizing drupal 10 theme development pdf
/themes/custom/my_theme/components/button/
├── button.component.yml
├── button.twig
├── button.css
└── button.js