Remove Mootools From Joomla Header

Joomla 1.5 is definitely a better CMS if you compare it to Joomla 1.0. One of few complaints I have heard and personally experienced with Joomla 1.5 is the inclusion of Mootools (and caption.js) by default if you use Joomla template method to display header information in your template. What’s the problem, one may ask? Well, the problem is that the Mootools file that comes with Joomla 1.5 is whopping 74k in size. From developer’s point of view, I may never need to use mootools in my application. And from end user point of view, this really slows down initial page load times especially for users who have slower connections, and you never get a second chance to make a first impression.Mootools is definitely a very useful JavaScript framework. (And since the perfectionist founder can even FIRE his developer, that also shows it has certain standard.) But loading it without using it really irritates some people.So why the hell on earth would Joomla 1.5 includes Mootools? The reason is because Joomla 1.5 Admin section uses Mootools. It’s the C (Controller) in the MVC (Model-View-Controller) that needs it. If you have installed the latest version and seen the AJAX effects from the admin area, you may probably know what I am talking about.Now the question is how to remove the Mootools and other JavaScript files from the header when the end users see it, and keep it exists when a administrator sees it? Don’t worry, here is the solution, below is the code I use to remove the mootools.js and caption.js

<?php
$user =& JFactory::getUser();
if ($user->get('guest') == 1) {
$headerstuff = $this->getHeadData();
$headerstuff['scripts'] = array();
$this->setHeadData($headerstuff); }
?>
<jdoc:include type="head" />

In case you want to keep the caption.js, (some Joomla! components, modules or plugins uses caption.js, for example:Acajoom), you can choose to remove mootools only. Below is the PHP code i use to do so:

<?php
// Remove auto generated mootool from header
$headerstuff = $this->getHeadData();
reset($headerstuff['scripts']);
$moo = key($headerstuff['scripts']);
unset($headerstuff['scripts'][$moo]);
$this->setHeadData($headerstuff);
?>
<jdoc:include type="head">

Hope these tips help!

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Technorati
  • Twitter
  • Yahoo! Bookmarks

About Shi Chuan

I am a web developer.
This entry was posted in Joomla! and tagged . Bookmark the permalink.

105 Responses to Remove Mootools From Joomla Header

  1. Ian says:

    Sweet! That made a big difference. It cut the total JS on my home page down from 27,722 Bytes down to 8,662. Thank you!

    • Ian says:

      Actually on further investigation I realized something. I may have spoken to soon. That bit of code messed up some stuff like font sizes and some things weren’t displaying properly on my site. I tried playing with both but they didn’t display properly. I’ll keep looking into this.

  2. Thank you!!! You do not know how much that helped! Really thank you!

  3. Miary Dev says:

    Hi all
    This code doesn’t work on Joomla! 2.5.
    To do the same, replace with :

    $this->_script = $this->_scripts = array();

    It works fine ;)
    Hope these help !

  4. Leo says:

    Hello,

    I have a big problem related to many js scripts being loaded on my homepage http://nadorpresse.com, loads a lot of CPU/RAM, trying to figure out what may cause the problem then I got to this discussion..

    I do not use a login/connextion module in my site, so i guess i can unload mootools and caption and that won’t cause problems to the rest of modules?

    If so where should I add the code? I’m using joomla 2.5

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">