mattgadient.com

Removing mootools.js and caption.js from Joomla

If you’ve tried to clean up your Joomla template, something may have perplexed you at one point or another. There’s no mention of mootools or caption.js in the template file, yet these 2 things end up in the HEAD section of all your pages anyway.

If your site is pretty basic, you probably don’t need them, and having them load every time just makes it that much more painful for your dial-up viewers. Heck, mootools.js alone is 74 kb !

So how do you get rid of mootools? It’s pretty simple code that you throw in your template’s HTML file. Hopefully, you know where the template is, but if not, you can find it one of two ways (you may want to back up first just in case!):

  • Browse to (and edit) the /templates/your-template-name/index.php file (located in the directory your website is in); or,
  • From within Joomla’s administrator panel, choose Extensions / Template Manager , then click on your template (probably the one with a star beside it), then choose “Edit HTML“.

Depending on how the permissions are set up on your server, one method may be easier than the other. Here’s the code you’re going to put in the template:

<?php
//remove mootools.js and caption.js
$headerstuff=$this->getHeadData();
reset($headerstuff[‘scripts’]);
foreach($headerstuff[‘scripts’] as $key=>$value){
unset($headerstuff[‘scripts’][$key]);
}
$this->setHeadData($headerstuff);
?>

Note that this goes near the top, right AFTER this:

<?php
// Prevent direct access sans Joomla!:
defined( ‘_JEXEC’ ) or die( ‘Restricted access’ );
?>

So once you’re done, the first few lines are probably going to look something like this (the blue is the stuff you’re adding):

<?php
// Prevent direct access sans Joomla!:
defined( ‘_JEXEC’ ) or die( ‘Restricted access’ );
?>

<?php
//remove mootools.js and caption.js
$headerstuff=$this->getHeadData();
reset($headerstuff[‘scripts’]);
foreach($headerstuff[‘scripts’] as $key=>$value){
unset($headerstuff[‘scripts’][$key]);
}
$this->setHeadData($headerstuff);
?>

<!DOCTYPE html PUBL……..

That’s it! Save, load up your website, make sure to hit refresh once (F5), and view the source – no more mootools or caption.js! Your website should load faster, and dial-up users can save their tears for another site.

A couple final things to note:

  1. Some Joomla templates (usually just the really fancy ones) may need mootools.js to operate properly. Make sure to check your template’s functionality afterwards.
  2. There are a few Joomla plugins/modules/components that require mootools as well. Many lightbox modules do for example, and you may find that many image/photo/video galleries do as well.

If you have any issues, just remove that bit of code from your template and you should be good to go again.

——

Finally, as much as I’d like to take credit for the above, credit goes to someone on the Joomla forums who posted it long ago (I don’t recall who it was, or who came up with it in the first place).

 

  • on the move

    thanks, this guide helped me take out mootools

  • WOW — getting rid of those two .js cut my load time in half!