5

Joomla 2.5中,以下脚本会自动加载。

<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>

我不想加载这些文件。如何删除这些链接?

4

3 回答 3

8

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]);
            }
        }
    }
?>
于 2012-12-07T09:25:14.947 回答
3
于 2012-12-07T08:56:09.157 回答
0

I used this code to remove jquery files from the head ( Joomla! 3.3.1 )

<?php

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

<jdoc:include type="head" />
于 2014-07-22T20:11:32.100 回答