Skip to main content

Removing useless jQuery scripts in Joomla

By default, Joomla core and other 3rd-party extensions loads bundled jQuery from JUI:

JHtml::_('jquery.framework');

Additionally, with /media/jui/js/jquery.min.js two more scripts are always loaded:

/media/jui/jquery-noconflict.js
/media/jui/jquery-migrate.min.js

But if your website doesn't use old deprecated MooTools and there are no issues with JUI version of jQuery (v1.12.4), you can disable loading of these extra scripts to reduce the number of requests.

Just pre-load jQuery framework with the scripts disabled:

JHtml::_('jquery.framework', false, false, false);

Add this code before the component is dispatched, i..e before the system plugin class declaration or use the onAfterRoute event.

Additionally, you can remove these scripts right in your Joomla template by unsetting the elements from JFactory::getDocument()->_scripts array referenced as $this->_scripts in template's index.php file.

Joomla 4 notes:

Joomla 4 introduced WEB asset manager which has the special code:

$this->getWebAssetManager()->disableScript('jquery');
$this->getWebAssetManager()->disableScript('jquery-noconflict');
$this->getWebAssetManager()->disableScript('jquery-migrate');

But note that another scripts can have jQuery as dependency and the files will still be included.