10

How do I disable the loading of

  • mootools-core.js
  • core.js

In <head> without using a third party component/plugin?

2
  • What version of Joomla are you using?
    – TryHarder
    Apr 23, 2014 at 0:11
  • @moomoochoo I am using joomla 3.2
    – web-tiki
    Apr 23, 2014 at 0:14

5 Answers 5

19

Im using Joomla 3.2, at the top of my tempate I put:

$doc = JFactory::getDocument();

$dontInclude = array(
'/media/jui/js/jquery.js',
'/media/jui/js/jquery.min.js',
'/media/jui/js/jquery-noconflict.js',
'/media/jui/js/jquery-migrate.js',
'/media/jui/js/jquery-migrate.min.js',
'/media/jui/js/bootstrap.js',
'/media/system/js/core-uncompressed.js',
'/media/system/js/tabs-state.js',
'/media/system/js/core.js',
'/media/system/js/mootools-core.js',
'/media/system/js/mootools-core-uncompressed.js',
);

foreach($doc->_scripts as $key => $script){
    if(in_array($key, $dontInclude)){
        unset($doc->_scripts[$key]);
    }
}

This prevents those scripts from being included, add or remove scripts as needed

1
  • 3
    This failed on my last project (joomla 3.3.6). I added JURI::root(true). before the script paths and it worked.
    – web-tiki
    Oct 28, 2014 at 16:06
5

You can unset it in the template

unset(
  $this->_scripts['/media/jui/js/mootools-core.js'],
  $this->_scripts['/media/jui/js/core.js']);

This will remove the both JS files from the Header.

4

In Joomla 3.x, you can call JHtml::_('jquery.framework') in your template to load jQuery without Mootools. This loads jQuery in no conflict mode by default so if you need normal mode, just add a second parameter of false: JHtml::_('jquery.framework', false).

http://docs.joomla.org/J3.2:Javascript_Frameworks

2

I've used this:

foreach ($doc->_scripts as $script => $value)
{
    if (preg_match('/media\/jui/i', $script))
      unset($doc->_scripts[$script]);
}
1
  • 2
    Since your needle string is not variable and the only intention is to make a case-insensitive match, then it would be better practice to use stripos() ... if (stripos($script, 'media/jui') !== false) Nov 30, 2018 at 0:40
0

The solution by @ContextSwitch wasnt working for me due to some scripts were being loaded after the template was processed so unsetting the files at that stage had no effect on those files.

So I had to implement the similar solution but using a simple plugin bound to onBeforeCompileHead event. As described by me here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.