Mootools optimization

Discussion regarding Joomla! 1.5 Performance issues.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Security and Performance FAQs
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Schizoid21
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Sat Feb 02, 2008 6:50 pm
Contact:

Re: Mootools optimization

Post by Schizoid21 » Mon Mar 10, 2008 6:03 pm

Code: Select all

<?php  
ob_start ("ob_gzhandler"); 
header("Content-type: text/javascript; charset: UTF-8"); 
header("Cache-Control: must-revalidate"); 
$offset = 60 * 60 ; 
$ExpStr = "Expires: " .  
gmdate("D, d M Y H:i:s", 
time() + $offset) . " GMT"; 
header($ExpStr); 
?> 
It's a code I found while googling "javascript gzip"

It reduces my files very nicely and it makes my joomla score better on website speed tests. I don't know if it's actually faster though...
Teaching myself a Healthy Lifestyle: http://www.prohealthblog.com

User avatar
newart
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3177
Joined: Fri Sep 02, 2005 10:06 am
Location: Solar system - Earth - European Union

Re: Mootools optimization

Post by newart » Tue Mar 11, 2008 7:01 am

I don't know how much better can be but I have to test it in my site - up to now I have avoided all java / mootools stuff... but in the future if I cannot do the same I need a knowledge for mastering this issue... ;)

About the option to turn off a mootools option as a wishlist for future version of joomla, I have posted the thread link for a contribute... anyone? It's important!
former Q&T WorkGroup Joomla member - Italian Translation Team Member

ghazal
Joomla! Explorer
Joomla! Explorer
Posts: 343
Joined: Fri Aug 19, 2005 12:12 pm
Location: Out of my mind ...sometimes

Re: Mootools optimization

Post by ghazal » Wed Mar 12, 2008 10:51 am

I had lost this very precious link and found it again.
Here:
http://icebeat.bitacoras.com/mootools/packito/

you will be able to send a .js mootools-related-file and that will show the components (mootools-speak) it uses.
Try the example.

User avatar
newart
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3177
Joined: Fri Sep 02, 2005 10:06 am
Location: Solar system - Earth - European Union

Re: Mootools optimization

Post by newart » Wed Mar 12, 2008 3:02 pm

in a joomla concern pls can you explain us by an example? I don't know how to manage that.
former Q&T WorkGroup Joomla member - Italian Translation Team Member

User avatar
MorfiusX
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Thu Dec 13, 2007 3:30 pm
Location: Ohio
Contact:

Re: Mootools optimization

Post by MorfiusX » Wed Mar 12, 2008 6:07 pm

newart wrote:"the second involved adding a php code before the javascript code. Now my mootools file is about 11000 in size"

please post here your code... also if we know the problem would be resolved at the best in a whitepaper forum... ;)
Here is the complete code:

Code: Select all

<?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>
I have also updated the article on my blog:
http://c3ohio.com/blog/mootools-optimiz ... dated.html

Hope this helps!

User avatar
newart
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3177
Joined: Fri Sep 02, 2005 10:06 am
Location: Solar system - Earth - European Union

Re: Mootools optimization

Post by newart » Wed Mar 12, 2008 7:59 pm

surely! And also I hope to see an option on/off for mootools stuff in a Joomla site... I'v just visited the white paper thread and I've seen that it gets a lot of interest by forumers
former Q&T WorkGroup Joomla member - Italian Translation Team Member

ghazal
Joomla! Explorer
Joomla! Explorer
Posts: 343
Joined: Fri Aug 19, 2005 12:12 pm
Location: Out of my mind ...sometimes

Re: Mootools optimization

Post by ghazal » Thu Mar 13, 2008 12:42 pm

@newark
in a joomla concern pls can you explain us by an example? I don't know how to manage that.
Ok, as a library, mootools is composed of a core file, to which one can adds snippets of scripts (or widgets, or components, or whatever you name it), according to one's needs.
The whole stuff is here : http://mootools.net/download
Packito is a kind of screening that shows which "components" are included in a mootools related file

Screening the mootools file included in the joomla package with packito, one can see that it doesn't include all the components showing on the mootools download page. Try it with the modal.js file in media/system/js/ for example (beware the security constraints of joomla)

Here is a snapshot of the screening by packito of the mootools file included in the joomla package :

http://img100.imageshack.us/img100/2305 ... olszb9.png

Hope it helps.

User avatar
newart
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3177
Joined: Fri Sep 02, 2005 10:06 am
Location: Solar system - Earth - European Union

Re: Mootools optimization

Post by newart » Thu Mar 13, 2008 5:53 pm

thanx a lot! Your post is very clear and complete, now I've understood everything! All is very easy now... :laugh:

But pls what's your thoughts about an option for mootools? Sometimes you can need a lighter and speeder joomla...
former Q&T WorkGroup Joomla member - Italian Translation Team Member

User avatar
MorfiusX
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Thu Dec 13, 2007 3:30 pm
Location: Ohio
Contact:

Re: Mootools optimization

Post by MorfiusX » Thu Mar 13, 2008 6:14 pm

newart wrote:thanx a lot! Your post is very clear and complete, now I've understood everything! All is very easy now... :laugh:

But pls what's your thoughts about an option for mootools? Sometimes you can need a lighter and speeder joomla...
I personally think that they should allow mootools.js and caption.js overrides on the front end like they do other elements in templates. So, if you have a js/mootools.js in your template directory, that will be used on the front end. Same would apply to js/caption.js.

The other option would be to have a simple checkbox in the global config to enable or disable the built in mootools.js and/or caption.js.

I've checked out the post on the whitepapers forum. It seams that some people are for, and some people are against the inclusion of mootools in 1.5. If there is one thing I've learned from Linux over the years, it's that choice is good. I don't think a hard yes or no is the right solution. There should be the option of yes or no so that that the user can decide.

Just my 1.5 cents...

ghazal
Joomla! Explorer
Joomla! Explorer
Posts: 343
Joined: Fri Aug 19, 2005 12:12 pm
Location: Out of my mind ...sometimes

Re: Mootools optimization

Post by ghazal » Thu Mar 13, 2008 8:03 pm

MorfiusX wrote: it's that choice is good. I don't think a hard yes or no is the right solution. There should be the option of yes or no so that that the user can decide.
I have been "lobbying" (sort of) for the "choice option" for months on several posts in several threads.
And this topic is becoming kind of significant now that a new version of mootools (1.2 stable) is about to come out.
I have made a number of tests with it and about a 25/30% of stuff developed with 1.11 wont work with 1.2, even with what mootools team calls the "compatible version".
Too bad, because this new version is much easier to understand and very often needs less code. Ultra-compressed, it weighs around 55k, all components included.

BTW, tks again to you and your snippet of code, MorfiusX, if I have been able to test it in j!.1.5, with switch/case my friend.

User avatar
newart
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3177
Joined: Fri Sep 02, 2005 10:06 am
Location: Solar system - Earth - European Union

Re: Mootools optimization

Post by newart » Fri Mar 14, 2008 1:40 pm

@ MorfiusX - me too I like to choose instaed of a yes or not... I agree with you, I hope you have posted your opinion in the white paper thread, if not could you post there? I hope to see an option like that! ;)
former Q&T WorkGroup Joomla member - Italian Translation Team Member

User avatar
MorfiusX
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Thu Dec 13, 2007 3:30 pm
Location: Ohio
Contact:

Re: Mootools optimization

Post by MorfiusX » Fri Mar 14, 2008 8:05 pm

newart wrote:@ MorfiusX - me too I like to choose instaed of a yes or not... I agree with you, I hope you have posted your opinion in the white paper thread, if not could you post there? I hope to see an option like that! ;)
I am going to join the discussion in the whitepaper forum. I just haven't had a lot of time with work and all. I had planned on trying to get to it this weekend.

User avatar
newart
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3177
Joined: Fri Sep 02, 2005 10:06 am
Location: Solar system - Earth - European Union

Re: Mootools optimization

Post by newart » Sat Mar 15, 2008 4:07 pm

Very good, I'm sure it's important your own contribute! Waiting, so... :)
former Q&T WorkGroup Joomla member - Italian Translation Team Member

User avatar
MorfiusX
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Thu Dec 13, 2007 3:30 pm
Location: Ohio
Contact:

Re: Mootools optimization

Post by MorfiusX » Sun Mar 16, 2008 10:23 pm

I have written a new article on How to super compress Mootools. Some might find it helpful.

I weighed in with my opinions in the Whitepaper forum. I also created a new whitepaper about using a better compressor for the default mootools.js file. It can be found here:
http://forum.joomla.org/viewtopic.php?f=500&t=275575

jkaufmann
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Tue Mar 18, 2008 12:13 am

Re: Mootools optimization

Post by jkaufmann » Tue Mar 18, 2008 12:42 am

I wanted to thank all the posting in this forum, but wanted to add one more thing I did to GREATLY decrease the mootools size. From the original 74K, down to ~40K thanks to this forum, and then down to ~17K w/ this compression script.

Please if anyone has any changes, post them here.

Just go into your template index.php files and replace all references to mootools.js or any others .css with something like the following:

Code: Select all

<link rel="stylesheet" href="<?php echo $this->baseurl; ?>/templates/system/gzipcache.php?files=mootools.js,othercode1.js,othercode2.js" type="text/javascript" />
Of course, save the following code in a file gzipcache.php along side every css and js file you want to compress.

Code: Select all

<?php

ob_start('ob_gzhandler');

$files = $_GET["files"];

$found = false;

$filearray = explode(",", $files);
foreach ($filearray as $f)
{
	if (substr($f, -4) == ".css")
	{
		header('Content-Type: text/css; charset: UTF-8');
		$found = true;
		$ext = ".css";
		$extlength = -4;
		break;
	}
	else if (substr($f, -3) == ".js")
	{
		header('Content-Type: text/javascript; charset: UTF-8');
		$found = true;
		$ext = ".js";
		$extlength = -3;
		break;
	}
}

if (!$found || !isset($ext) || !isset($extlength))
{
	die("Invalid Call");
	return;
}

header('Cache-Control: must-revalidate');

$expire_offset = 0; // set to a reaonable interval, say 3600 (1 hr)
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expire_offset) . ' GMT');

foreach ($filearray as $f)
{
	if (substr($f, $extlength) == $ext)
	{
		if ($ext == ".css")
			dump_css_cache($f);
		else
			echo file_get_contents($f);
	}
}

//Now the functions

function css_compress($buffer) {
  $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);// remove comments
  $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  '), '', $buffer);// remove tabs, spaces, newlines, etc.
  $buffer = str_replace('{ ', '{', $buffer);// remove unnecessary spaces.
  $buffer = str_replace(' }', '}', $buffer);
  $buffer = str_replace('; ', ';', $buffer);
  $buffer = str_replace(', ', ',', $buffer);
  $buffer = str_replace(' {', '{', $buffer);
  $buffer = str_replace('} ', '}', $buffer);
  $buffer = str_replace(': ', ':', $buffer);
  $buffer = str_replace(' ,', ',', $buffer);
  $buffer = str_replace(' ;', ';', $buffer);
  return $buffer;
}

function dump_css_cache($filename) {
  $cwd = getcwd() . DIRECTORY_SEPARATOR;

  $stat = stat($filename);
  $current_cache = $cwd . $filename . '.' . $stat['size'] . '-' . $stat['mtime'] . '.cache';

  // the cache exists - just dump it
  if (is_file($current_cache)) {
    include($current_cache);
    return;
  }

  // remove any old, lingering caches for this file
  if ($dead_files = glob($cwd . $filename . '.*.cache', GLOB_NOESCAPE))
    foreach ($dead_files as $dead_file)
      unlink($dead_file);
 
  if (!function_exists('file_put_contents')) {
    function file_put_contents($filename, $contents) {
      $handle = fopen($filename, 'w');
      fwrite($handle, $contents);
      fclose($handle);
    }
  }
 
  $cache_contents = css_compress(file_get_contents($filename));
  file_put_contents($current_cache, $cache_contents);
 
  echo $cache_contents;
}
?>
This code will strip down all CSS files of unnecessary characters, and then cache it in a file to save from having to do it for every page load. It will also attach all the header info to send javascript and CSS files encrypted using gzip, which will cut text based files down to more than half their original size. In addition, this file will combine any javascript and css files you have, which can greatly reduce page load time b/c there is overhead latency for each file a browser has to retrieve, so its better to have 1 css file as opposed to 10 that all sum up to the same size.

Davor
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Thu Mar 02, 2006 2:18 pm
Contact:

Re: Mootools optimization

Post by Davor » Sat May 31, 2008 11:42 am

As I am absolute MooTools newbie, I would highly appreciate if someone could take a look at my website:

http://www.inter-serbia.net

Apart of the big images that I will optimize, I see there are 2 mootools scripts running. Is this normal or not? On my laptop I am experiencing slowdowns in FF, not in IE. On my home PC everything is running fine. I also received complaint from my hosting company, claiming that my site is very CPU heavy.

Thx in advance.

Davor

seenguyen
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Thu Jan 04, 2007 3:57 pm
Contact:

Re: Mootools optimization

Post by seenguyen » Sat Sep 13, 2008 6:09 pm

@ jkaufmann: hi,

Could you advice me more about the gzipcache.php?
I did change the template index.php file and put the gzipcache.php to the folders which contents the .css & .js then I got the clear site, without style!

Thanks

User avatar
newart
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3177
Joined: Fri Sep 02, 2005 10:06 am
Location: Solar system - Earth - European Union

Re: Mootools optimization

Post by newart » Mon Sep 15, 2008 10:50 am

very interesting but me too I need more info about the gzipcache.php - thanx a lot for your tips!

(waiting for an option on/off for mootools activation...)
former Q&T WorkGroup Joomla member - Italian Translation Team Member

User avatar
yerg
Joomla! Ace
Joomla! Ace
Posts: 1016
Joined: Thu Aug 18, 2005 12:22 pm
Location: Ballarat, Australia
Contact:

Re: Mootools optimization

Post by yerg » Wed Nov 19, 2008 7:32 am

My first port of call was here http://dean.edwards.name/packer/

it reduced the size of the file bu around 50% and it's really made things zippy

May do other js files as well
We cannot become what we need to be ... by remaining what we are

User avatar
newart
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3177
Joined: Fri Sep 02, 2005 10:06 am
Location: Solar system - Earth - European Union

Re: Mootools optimization

Post by newart » Thu Nov 20, 2008 6:12 pm

interesting link for an interesting on-line compressor, thanx a lot!
former Q&T WorkGroup Joomla member - Italian Translation Team Member

User avatar
SiriusOCT
Joomla! Intern
Joomla! Intern
Posts: 61
Joined: Sun Jan 14, 2007 1:18 pm
Location: Paris
Contact:

Re: Mootools optimization

Post by SiriusOCT » Sat Nov 22, 2008 4:01 pm

Hi all,

my mootools is 20.1K (original is 74.2K)

Just try this: http://forum.joomla.org/viewtopic.php?f=433&t=344013

But if you want some compressors:

Dojo Online

Packer in PHP

Code & Coffee (JSMin)
Joomla 3.9.24 | PHP 7.4.14 + APC | MariaDB 10.2.36 | Litespeed

Pixelsmith
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Sun Nov 02, 2008 5:47 pm

Re: Mootools optimization

Post by Pixelsmith » Sun Feb 08, 2009 9:45 pm

Hi there.

I'm a relative newcomer to joomla and web development, but have taught myself how to use it with these forums and Google, in my spare time over the last four months or so. I have run into a site-breaking problem and would really appreciate it if anyone had any input.

My joomla site (http://www.rollzero.com) was slow to load, so I used the following php script in the template html file to disable Mootools (which was loading twice):

Code: Select all

<?php
// Remove mootool sripts for guest and registered
    $user =& JFactory::getUser();
    if ($user->get('guest') == 1 or $user->usertype == 'Registered' or $user->usertype == 'Super Administrator') {
        $headerstuff = $this->getHeadData();
        $headerstuff['scripts'] = array();
        $this->setHeadData($headerstuff);
    }
?>
I found it here: http://forum.joomla.org/viewtopic.php?f=501&t=266809

Supposedly this just disables Mootools for the frontend. But I found problems with the admin backend - Tiny MCE took 40 seconds or more to load up, and Firefox lagged for 20 seconds when i used the image uploader to browse for files.

So I removed the php code. Unfortunately I still have the same problems with the backend - and Mootools still does not load for the front page. It has also stopped my instances of the GK_News_Show_3 module from working properly - now they only take layout info from the template CSS, and not from their own php files.

Has anybody encountered this error or a solution?

Stupidly I changed a couple of other things at the same time, although I'm not sure if they are relevant. As per suggestions in the joomla security wiki, I changed the name of the log and tmp folders (via ftp and in the global config), removed a load of leftover zips and directories from within that tmp folder, and also removed the templates I wasn't using (so I now only have mine installed). I also disabled JCE Editor, JCE utilities and MediaObject - all to speed up the front page. Re-enabling these doesn't remove my current problem.

Sorry for the lengthy post. I'm at a bit of a loss about what to do and would be really grateful for any insight.

Oh, I'm using Joomla 1.5.9.

Thank you in advance,
Pixelsmith.

User avatar
yerg
Joomla! Ace
Joomla! Ace
Posts: 1016
Joined: Thu Aug 18, 2005 12:22 pm
Location: Ballarat, Australia
Contact:

Re: Mootools optimization

Post by yerg » Sun Feb 08, 2009 10:03 pm

For speeding up administration tasks I'd suggest you install Google Gears - see the extensions site.

Your template may be loading MooTools twice so I'd check that

HAve you tried compressing that file as this thread is about
We cannot become what we need to be ... by remaining what we are

joeguo
Joomla! Apprentice
Joomla! Apprentice
Posts: 38
Joined: Thu Apr 24, 2008 6:14 am

Re: Mootools optimization

Post by joeguo » Tue Feb 10, 2009 12:39 pm

Just host Mootools on Google, please use the plugin:
http://extensions.joomla.org/extensions ... 81/details

User avatar
newart
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3177
Joined: Fri Sep 02, 2005 10:06 am
Location: Solar system - Earth - European Union

Re: Mootools optimization

Post by newart » Tue Feb 10, 2009 3:35 pm

joeguo it's a Great idea! In that case you can save bandwidth obviously (moreover speeding your site up). It can be a good choice but it has to be a choice in our Joomla!

Now there is a "fixed" CMS system in which you cannot decide what doing about java files...

Your link is good for explaining that if new versions of our Joomla! ( 1.6 ? ) has an option, well, it can be an optimum decision for an ever better system - please remember us that Joomla stands for flexible... ;)

I hope somebody can hear me/us :'(
former Q&T WorkGroup Joomla member - Italian Translation Team Member

capermak
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Sat Feb 07, 2009 10:20 am

Re: Mootools optimization

Post by capermak » Tue Feb 10, 2009 4:59 pm

MorfiusX wrote:I have been trying to optimize my site http://c3ohio.com . Using the optimizer at http://www.websiteoptimization.com/services/analyze/, I see that mootools.js is by far the largest file that gets loaded. In fact, it's over half of the size of my page. I have tried to use a custom mootools.js from http://mootools.net/. My page loads fine, but I get a JavaScript error in IE. How can I trace what is causing the error so I make sure to include those functions in the custom mootools.js? Even when I selected all components, the file was only ~40k, while the native 1.5 file size is ~70k. Where are the extra 30k coming from? Thanks!
- I tried this, note - mootools 1.21 is what I found there - I made a custom file, including all the options as you stated, and simply replaced mootools.js in the appropriate folder. - I then started getting IE error notifications... I am assuming that J1.5 uses a previous version of mootools? and thats whats causing this?

I ended up with a moostools.js at about 60k, not ~40k

BTW, in the meantime, I started using smartoptimizer, have you checked this out? any comments? security risks?

User avatar
SiriusOCT
Joomla! Intern
Joomla! Intern
Posts: 61
Joined: Sun Jan 14, 2007 1:18 pm
Location: Paris
Contact:

Re: Mootools optimization

Post by SiriusOCT » Tue Feb 10, 2009 6:10 pm

newart wrote:joeguo it's a Great idea! In that case you can save bandwidth obviously (moreover speeding your site up). It can be a good choice but it has to be a choice in our Joomla!
Yes, not bad, but the bandwidth is not always the priority.
Because with the plugin Google’s AJAX Libraries API:
joeguo wrote:Just host Mootools on Google, please use the plugin:
http://extensions.joomla.org/extensions ... 81/details
You get one more DNS lookup, and if for some reasons the library is unreachable, it turns weird.
You see what I mean, for example sometimes this is the case with the Google Ads, when they're not responding, all the site is slowdown.

To have the library on the local server is more secure (by my side)
Joomla 3.9.24 | PHP 7.4.14 + APC | MariaDB 10.2.36 | Litespeed

ghazal
Joomla! Explorer
Joomla! Explorer
Posts: 343
Joined: Fri Aug 19, 2005 12:12 pm
Location: Out of my mind ...sometimes

Re: Mootools optimization

Post by ghazal » Wed Oct 24, 2012 10:39 am

Hi,
maybe you should try this :
Mootools Enabler/Disabler - Joomla! Extensions Directory

http://extensions.joomla.org/extensions ... ools/22236


Locked

Return to “Performance - Joomla! 1.5”