Remove CSS and Scripts in Joomla
There are cases where you would like to remove or disable unnecessary CSS and JavaScript files from your Joomla site output. This is a common task: removing styles and scripts to improve performance, avoid file conflicts, and keep pages lighter. Hopefully, you don't need an extra plugin. You can do it with Tassos Code Snippets using a simple PHP snippet.
The PHP Snippet Code
This code removes specific CSS and JS assets before Joomla renders the <head> section, so you can safely control which files are loaded on your frontend pages.
use Joomla\CMS\Factory;
// Edit these asset names.
$unwantedcss = [
'bootstrap.css',
'template.custom',
];
$unwantedjs = [
'jquery',
'core',
];
// Do not edit below.
$app = Factory::getApplication();
$app->registerEvent('onBeforeCompileHead', function() use ($app, $unwantedcss, $unwantedjs)
{
$document = $app->getDocument();
if (!$document || $document->getType() !== 'html')
{
return;
}
$wa = $document->getWebAssetManager();
$styles = array_filter(array_map('trim', $unwantedcss));
foreach ($styles as $style)
{
if ($wa->assetExists('style', $style))
{
$wa->disableAsset('style', $style);
}
}
$scripts = array_filter(array_map('trim', $unwantedjs));
foreach ($scripts as $script)
{
if ($wa->assetExists('script', $script))
{
$wa->disableAsset('script', $script);
}
}
});
How to add this snippet
- Install Tassos Code Snippets if it is not installed already.
- Go to your Joomla Administrator area.
- Open Components → Tassos Code Snippets.
- Click New.
- Select PHP as the snippet type.
- Paste the remove styles and scripts code above.
- Select Insertion Method → Page Load.
- Publish the snippet.
- Optionally, open the Conditional Logic tab to restrict which pages or users the snippet runs on. Leave it empty to run it site-wide. Learn more in Using Snippet Logic.
Congratulations! You've just added the ability to remove CSS and JS in Joomla without installing another plugin or adding unnecessary bloat to your site. To learn more details, visit the PHP Snippet documentation:
Use Cases
- Remove legacy MooTools files not used anymore
- Remove duplicate Bootstrap CSS/JS loaded by multiple extensions
- Prevent conflicting libraries from loading together
- Improve page speed by reducing unnecessary requests
- Keep frontend asset output cleaner on selected pages
Last updated on Mar 9th 2026 15:03
In This Article