miercuri, 5 martie 2014

Stop Loading Automatic Scripts in Joomla 2.5

Problema de optimizare a vitezei site-ului.

Javascript-ul trebuie sa se incarce asincron in pagina - http://gtmetrix.com/defer-parsing-of-javascript.html

Pentru asta, trebuie ca scripturile sa aiba forma <script asyn>. Ideea este ca trebuie introduse in momentul in care se genereaza documentul.
Pentru asta, aflam informatii de aici:

http://stackoverflow.com/questions/13758204/stop-loading-automatic-scripts-in-joomla-2-5

adica
Aici se opreste incarcarea mootools.js, eu nu am nevoie de asta.
accepted
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]);
            }
        }
    }
?>