Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Loading Automatic Scripts in Joomla 2.5

Tags:

joomla

In Joomla 2.5, the scripts below are loaded automatically.

<script src="/media/system/js/mootools-core.js" type="text/javascript"></script>
<script src="/media/system/js/core.js" type="text/javascript"></script>
<script src="/media/system/js/caption.js" type="text/javascript"></script>
<script src="/media/system/js/mootools-more.js" type="text/javascript"></script>
<script src="/templates/pswedge/js/jquery.min.js" type="text/javascript" defer="defer"></script>

I don't want to load these files. How can I remove these links?

like image 603
Zahid Habib Avatar asked Dec 07 '12 06:12

Zahid Habib


2 Answers

I would not recommend you to change the core files of Joomla.But if you really need to that then you can try this:

Step to disable the preloaded script file in joomla template.

Step one: Using your favorite file editor, open for edit:

/libraries/joomla/document/html/renderer/head.php

Step one: Find this code at line 151 and update it to include the code with this :

// Generate script file links
foreach ($document->_scripts as $strSrc => $strAttr)
{
    // Code to disable mootools for your site (still loads it for your admin)

    $ex_src = explode("/",$strSrc);
    $js_file_name = $ex_src[count($ex_src)-1];
    $js_to_ignore = array("mootools-core.js","mootools-more.js","core.js","caption.js");
    if( in_array($js_file_name,$js_to_ignore) AND substr_count($document->baseurl,"/administrator") < 1 AND $_GET['view'] != 'form')
        continue;

    $buffer .= $tab . '<script src="' . $strSrc . '"';
    if (!is_null($strAttr['mime']))
    {
        $buffer .= ' type="' . $strAttr['mime'] . '"';
    }
    if ($strAttr['defer'])
    {
        $buffer .= ' defer="defer"';
    }
    if ($strAttr['async'])
    {
        $buffer .= ' async="async"';
    }
    $buffer .= '</script>' . $lnEnd;
}

After saving the changes above, clear the cache that you have set and test your Joomla website and your Joomla Admin Dashboard. If you view the source code,all the predefind files are not there.

Or

You can try like this to hide it from index.php in template. Just put this line before the <jdoc:include type="head" /> and make necessary changes as needed to the scripts.

<?php 
    $search = array('mootools-more.js', 'caption.js');
    // remove the js files
    foreach($this->_scripts as $key => $script) {
        foreach($search as $findme) {
            if(stristr($key, $findme) !== false) {
                unset($this->_scripts[$key]);
            }
        }
    }
?>
like image 82
Toretto Avatar answered Nov 10 '22 07:11

Toretto


May one of these method work-

Method 1: Put Before <jdoc:include type="head" />

$search = array('mootools', 'caption.js');
    // remove the js files
    foreach($this->_scripts as $key => $script) {
        foreach($search as $findme) {
            if(stristr($key, $findme) !== false) {
                unset($this->_scripts[$key]);
            }
        }
    }

//Method 2

in index.php of template

$parameter_script = 'scripts'; 
$headerstuff=$document->getHeadData();
reset($headerstuff[$parameter_script]);
foreach($headerstuff[$parameter_script] as $key=>$value){
unset($headerstuff[$parameter_script][$key]);     
}
$document->setHeadData($headerstuff);

//Method 3

In the file directory /plugins/system create a new file called “removemootools.php” and insert the following code (you will need to register the plugin in the database, too).

class plgSystemRemoveMooTools extends JPlugin
{
public function onAfterDispatch()
{
$app = JFactory::getApplication();
if($app->isSite()) //Only ever remove MooTools from the client-side, never the admin side
{
//Repeat these three line for all js you want to exclude
$mootools = JURI::root(true).DS.'media'.DS.'system'.DS.'js'.DS.'mootools.js';
$document = JFactory::getDocument();
unset($document->_scripts[$mootools]);
}
}
}
like image 44
Irfan Avatar answered Nov 10 '22 07:11

Irfan