ASSET-ADDSCRIPT-001
$doc->addScript()
addScript() / addStyleSheet() vs WebAssetManager
addScript/addStyleSheet still exist but they skip dependency order, versioning, and WebAssetManager. Joomla 4+ templates and extensions should declare assets in joomla.asset.json.
$doc->addScript() → WebAssetManager + joomla.asset.json
Symptoms people search
scripts load in the wrong order · jquery not defined because it loaded after my file · css missing after upgrade
Replace this code
Swap $doc->addScript() for WebAssetManager + joomla.asset.json.
Joomla 3
Remove or stop calling this
$doc = JFactory::getDocument();
$doc->addScript(JUri::root() . 'media/com_lms/js/lms.js');
$doc->addStyleSheet(JUri::root() . 'media/com_lms/css/lms.css');Joomla 4 / 6
Use this instead
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->useStyle('com_lms.lms')->useScript('com_lms.lms');
// Register those names in media/com_lms/joomla.asset.jsonHow to fix it
- 1Add media/.../joomla.asset.json with named assets.
- 2Replace addScript/addStyleSheet with $wa->useScript / useStyle.
- 3Move inline JS to addInlineScript via WAM.
Also known as
addScript · addStyleSheet · WebAssetManager · joomla.asset.json · WAM
Related issues
- Joomla 3 → 4JavaScript
behavior.framework (MooTools)
JHtml::_('behavior.framework') → Do not load MooTools — use vanilla JS or WebAssetManager
- Joomla 3 → 4JavaScript
JHtmlBootstrap::modal()
JHtmlBootstrap::modal() → HTMLHelper::_('bootstrap.renderModal')
- Joomla 3 → 4JavaScript
Chosen.js (formbehavior.chosen)
JHtml::_('formbehavior.chosen') → Core styled <select>, Choices.js, or Tom Select
- Joomla 5 → 6JavaScript
Assuming jQuery is always on the page
JHtml::_('jquery.framework') → Declare jQuery in joomla.asset.json only if you still need it
- Joomla 5 → 6JavaScript
Joomla.JText (JavaScript)
Joomla.JText._() → Joomla.Text._() + Text::script() in PHP
- Joomla 4 → 5Templates
Template without joomla.asset.json
templateDetails.xml only → joomla.asset.json + WebAssetManager in index.php