PHP
Joomla! 6
Joomla! 5
Joomla! 4
Template
Basic
Load Bootstrap 5 JavaScript Modules On Demand via WebAssetManager
Enqueues only the specific Bootstrap 5 JS components needed (collapse, dropdown, modal, offcanvas) instead of the full bundle.
templates/seu_template/index.php
<?php
declare(strict_types=1);
use Joomla\CMS\Factory;
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
// Carregue apenas os módulos realmente usados no layout
$wa->useScript('bootstrap.collapse')
->useScript('bootstrap.dropdown')
->useScript('bootstrap.modal');
Enqueues only individual ES modules rather than the monolithic bootstrap bundle.
Technical explanation and best practices
Joomla 5 and 6 ships individual Bootstrap 5 ES modules pre-registered in WebAssetManager. Loading only what your view uses keeps JavaScript payloads minimal for top Core Web Vitals scores.