Joomla 2.5 – Disable mootools

Mootools is a lightweight javascript framework used in Joomla 2.5. Your Joomla website will by default include both mootools-core.js (92.9 KB) and mootools-more.js (233 KB). Mootools is used mostly in your Joomla Admin Dashboard, it is not used often in Joomla templates.

UPDATE – 2012.05.11
After several months of testing Joomla 2.5 and various components, we have found that if you disable mootools you may break a lot of features. For example, while testing VirtueMart, we lost all search filter functionality. After enabling mootools, the problems were resolved. Therefore, we do not recommend disabling mootools. DISABLE MOOTOOLS AT YOUR OWN RISK.

If your Joomla website does not use mootools, it may benefit you to disable mootools. If you disable mootools in Joomla 2.5, you can:

  • Increase page download speed by removing 325.9 KB of un-needed javascript code
  • Reduce the number of conflicts caused between mootools and other javascript frameworks, such as jQuery

Steps to disable MooTools in Joomla 2.5

  1. Using your favorite file editor, open for edit:

    libraries/joomla/document/html/renderer/head.php

  2. Find this code at line 151:

    // Generate script file links
    foreach ($document->_scripts as $strSrc => $strAttr)
    {
        $buffer .= $tab . '<script src="' . $strSrc . '"';
        if (!is_null($strAttr['mime']))
        {
            $buffer .= ' type="' . $strAttr['mime'] . '"';
        }
        if ($strAttr['defer'])
        {
            $buffer .= ' defer="defer"';
        }
        if ($strAttr['async'])
        {
            $buffer .= ' async="async"';
        }
        $buffer .= '</script>' . $lnEnd;
    }

    … and update it to include the code (highlighted in green below):

    // Generate script file links
    foreach ($document->_scripts as $strSrc => $strAttr)
    {
        // Code to disable mootools for your site (still loads it for your admin)
        // Written by Brad Markle w/ InMotionHosting.com
        $ex_src = explode("/",$strSrc);
        $js_file_name = $ex_src[count($ex_src)-1];
        $js_to_ignore = array("mootools-core.js","mootools-more.js");
        if( in_array($js_file_name,$js_to_ignore) AND substr_count($document->baseurl,"/administrator") < 1 AND $_GET['view'] != 'form')
            continue;
    
        $buffer .= $tab . '<script src="' . $strSrc . '"';
        if (!is_null($strAttr['mime']))
        {
            $buffer .= ' type="' . $strAttr['mime'] . '"';
        }
        if ($strAttr['defer'])
        {
            $buffer .= ' defer="defer"';
        }
        if ($strAttr['async'])
        {
            $buffer .= ' async="async"';
        }
        $buffer .= '</script>' . $lnEnd;
    }
  3. After saving the changes above, clear any cache that you have set and test your Joomla website and your Joomla Admin Dashboard. If you view the source code, mootools should not load on your site but it will load in your Joomla Admin Dashboard.

Notes:

If your Joomla 2.5 Admin folder is not named “administrator”, update this section of code with the correct folder name:
substr_count($document->baseurl,”/administrator”)

If you would like to disable other scripts, such as caption.js, add it to the js_to_ignore array, as in:
$js_to_ignore = array(“mootools-core.js”,”mootools-more.js”,”caption.js”);

UPDATE – 2012.04.04
While writing other Joomla 2.5 tutorials, I’ve learned that the frontend article submission form requires mootools. If you disabled mootools and clicked the “Save” button when trying to save an article, nothing would happen. I updated the code above to include:

AND $_GET['view'] != 'form'

If you are on a form on your website, this line of code will allow mootools to load.

If you are experiencing any issues due to this modification, feel free to post a comment at the bottom of this page and we’ll be happy to review.

0 thoughts on “Joomla 2.5 – Disable mootools

  1. While I agree that it’s generally a bad idea to modify your core files, keeping good backups and proper documentation should mitigate the issues that crop up from update overwrites.

    Also…

    There are other lightbox options that do not require mootools. Personally I find it’s a lot easier to find a different solution then to figure out how to solve the host of conflicts that arise when you’re trying to use mootools AND jQuery, and given the choice, I’d rather keep jQuery.

  2. After disabling mootools some features stop working for me. lightbox for instance. when I click an image that should open as a lightbox, it directly navigates to the jpg file itself. enabling mootools solves the problem.

    1. Hello Hessam,

      Thank you for the information. As said in the disclaimer on the article, it may break several features. It seems that Lightbox is one of them. This may be helpful for anyone looking to disable mootools.

      Kindest Regards,
      Scott M

Was this article helpful? Join the conversation!