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

Dies at Joomla 4 → 5J3: Works nativelyJ4: Deprecated — do not shipJ6: Deprecated — do not shipBC plugin: not applicablePatch possible — review itJavaScript

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.json

How to fix it

  1. 1Add media/.../joomla.asset.json with named assets.
  2. 2Replace addScript/addStyleSheet with $wa->useScript / useStyle.
  3. 3Move inline JS to addInlineScript via WAM.

Also known as

addScript · addStyleSheet · WebAssetManager · joomla.asset.json · WAM

Related issues

Get in touch

Have a project in mind? Let's talk about it.

Tell us what you're building. Whether it's a new site, an online store, a mobile app, or something that needs AI under the hood, we'll get back to you within a business day.

Free consultation
No commitment, no pressure
Reply within 24 hours
Usually much faster

Prefer a direct conversation?

Request a project quote

Tell us about your project

Fill out the quick form and we'll reach out.