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 snippet disables CSS, JavaScript, and asset presets before Joomla renders the <head>, so you control exactly which files load on your frontend pages.

You don't need the exact asset name. Type any part of it and every matching asset is removed. For example, menu matches mod_menu.menu. Matching is case-insensitive.

use Joomla\CMS\Factory;
use Joomla\CMS\Document\HtmlDocument;

// Add any part of an asset name. 'menu' matches 'mod_menu.menu', 'bootstrap' matches
// 'bootstrap.css'. Matching is case-insensitive and matches anywhere in the name.
$unwanted = [
    'bootstrap.css',
    'mod_menu.menu',
];

// Asset types to search. 'preset' is included because names like 'mod_menu.menu' are
// registered as a preset that pulls in the matching script and style.
$types = ['style', 'script', 'preset'];

// Do not edit below.
$app = Factory::getApplication();

$app->registerEvent('onBeforeCompileHead', function () use ($app, $unwanted, $types)
{
    $document = $app->getDocument();

    if (!($document instanceof HtmlDocument))
    {
        return;
    }

    $needles = array_filter(array_map('strtolower', array_map('trim', $unwanted)));

    if (!$needles)
    {
        return;
    }

    $wa = $document->getWebAssetManager();

    foreach ($types as $type)
    {
        foreach ($wa->getAssets($type, true) as $asset)
        {
            $name = $asset->getName();

            foreach ($needles as $needle)
            {
                if (strpos(strtolower($name), $needle) !== false)
                {
                    $wa->disableAsset($type, $name);

                    // Uncomment to see which assets are being removed:
                    // $app->enqueueMessage('Removed ' . $type . ': ' . $name, 'notice');

                    break;
                }
            }
        }
    }
});

Tip: Keep each entry specific enough to match only what you want. A short fragment like core matches many assets, so prefer something distinctive such as bootstrap.css or mod_menu.menu. To see what a page loads, uncomment the enqueueMessage line in the snippet.

How to add this snippet

  1. Install Tassos Code Snippets if it is not installed already.
  2. Go to your Joomla Administrator area.
  3. Open ComponentsTassos Code Snippets.
  4. Click New.
  5. Select PHP as the snippet type.
  6. Paste the remove styles and scripts code above.
  7. Select Insertion MethodPage Load.
  8. Publish the snippet.
  9. 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 Jul 9th 2026 10:07