Mootools Optimizaion in Joomla 1.5 - Updated |
|
|
Written by Rick Winkler
|
|
Wednesday, 12 March 2008 |
Note: This article is an update to the previously posted article. If you have not read that article, I would suggest you start there.
I am going to be brief here and not explain all of the details. I am also assuming some basic knowledge of PHP and Joomla templating. If you have questions, please post a comment below or visit my thread at the Joomla forum .
Most people who are reading this are going to have one of the following goals concerning Mootools and Joomla 1.5: they want to remove it completely, or the want to minimize the size.
Removing Mootools completely
Simply removing mootools.js will cause a javascript error on the client because Joomla 1.5 also includes caption.js. Caption.js is dependant on mootools.js. In order to remove mootools.js, we also have to remove caption.js. Here is the code to do just that:
<?php
// Remove mootool sripts for guest and registered
$user =& JFactory::getUser();
if ($user->get('guest') == 1 or $user->usertype == 'Registered') {
$headerstuff = $this->getHeadData();
$headerstuff['scripts'] = array();
$this->setHeadData($headerstuff);
}
?>
This code goes into whatever template you are using. You want to place this above “<jdoc:include type="head" />” What this does is remove the two default generated javascript lines.
Optimizing Mootools
If you still need some of the functionality of Mootools, but not the whole library, then you can add a line back to your template to include a custom mootools.js file. After you remove the defaults above, then add the following line to your template:
<script type="text/javascript" src="<?php echo($this->baseurl); ?>
/templates/<?php echo($this->template); ?>/js/mootools.js"></script>
(This should be one line, sorry for the wrapping)
Notice that I created a "js" directory for my mootools.js in my template directory. You can place this anywhere you want, just make sure to update the path.
Put it Together
Once you put this all together, your final code should look similar to:
<?php
// Remove mootool sripts for guest and registered
$user =& JFactory::getUser();
if ($user->get('guest') == 1 or $user->usertype == 'Registered') {
$headerstuff = $this->getHeadData();
$headerstuff['scripts'] = array();
$this->setHeadData($headerstuff);
}
?>
<jdoc:include type="head" />
<script type="text/javascript" src="<?php echo($this->baseurl); ?>
/templates/<?php echo($this->template); ?>/js/mootools.js"></script>
Not only do you get a lot more control over the javascript files, this solution does not break any of the backend administration.
|