Joomla loads a bunch of scripts by default - many of these are necessary for something or other, but sometimes (if you know what you are doing) you may want to remove them or stop them from loading.
To do this, there is a specific function that you can use. Add the following to the index.php of your template.
Manual Code
Add or remove files from the dontInclude - the ones you add here will be unloaded. Anything which you do not include will not be unloaded.
$doc = JFactory::getDocument();
$dontInclude = array(
'/media/jui/js/jquery.js',
'/media/jui/js/jquery.min.js',
'/media/jui/js/jquery-noconflict.js',
'/media/jui/js/jquery-migrate.js',
'/media/jui/js/jquery-migrate.min.js',
'/media/jui/js/bootstrap.js',
'/media/system/js/core-uncompressed.js',
'/media/system/js/tabs-state.js',
'/media/system/js/core.js',
'/media/system/js/mootools-core.js',
'/media/system/js/mootools-core-uncompressed.js',
);
foreach($doc->_scripts as $key => $script){
if(in_array($key, $dontInclude)){
unset($doc->_scripts[$key]);
}
}
Joomla Plugin To Unload Scripts
There are quite a few plugins that allow you to remove such scripts if you don't want to include them. We use the Mootools Enabler / Disabler plugin by Roberto Segura which is tiny plugin, which unloads the plugin from everywhere except the places where it is required.
For example, you can choose the Auto enable the scripts for the users' login and for article addition.
We also use the same plugin to unload other stuff that we want to exclude by simply adding the URL of the JS file we want to exclude:
As you can see, we're dropping infinite scrolling and pagination scripts which are included by default in our template, but which we do not need - and would just add page loading time literally for nothing.
We're also dropping the ionicons CSS, which once again would just be unnecessary bloat.
In our quest to bring our site to load in as few milliseconds as possible, this tool has been a great addition.
Another alternative whose setup is a little more complicated is jQueryEasy. This is much more configurable, but usually makes sense in the hands of a developer who os very comfortable with Joomla.
Please leave a useful comment with your thoughts, then share this on your Facebook group(s) who would find this useful and let's reap the benefits together. Thank you for sharing and being nice!
Disclosure: This page may contain links to external sites for products which we love and wholeheartedly recommend. If you buy products we suggest, we may earn a referral fee. Such fees do not influence our recommendations and we do not accept payments for positive reviews.