Last Updated: February 25, 2016
·
12.08K
· codesbyaxel

Removing unnecessary code in your Joomla!-template

Are you annoyed by the unnecessary code loaded by Joomla! in the head-section of your Joomla!-website? By this I mean:

<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 type="text/javascript">
window.addEvent('load', function() {
new JCaption('img.caption');
});
</script>

With a few lines of PHP you can strip it down to a (necessary) minumum. Open the index.php in your Joomla!-template, remove all other PHP before the head-section, and replace it with this code:

<?php
defined('_JEXEC') or die;
unset($this->_scripts[JURI::root(true).'/media/system/js/caption.js']);
if (isset($this->_script['text/javascript']))
{ $this->_script['text/javascript'] = preg_replace('%window\.addEvent\    (\'load\',\s*function\(\)\s*{\s*new\s*JCaption\(\'img.caption\'\);\s*}\);\s*%',     '', $this->_script['text/javascript']);
if (empty($this->_script['text/javascript']))
unset($this->_script['text/javascript']);}
?>
<?php
defined( '_JEXEC' ) or die( 'Access Denied.' );
// Remove mootools and other scripts from header
$this->_scripts = array();?>

These lines of PHP removes all the MooTools-scripts, and the annoying JCaption-code.

1 Response
Add your response

Show it was that i need, but i need change it to use this:
'%jQuery(window).on(\'load\', function() {\n.?new JCaption(\'img.caption\');\n(.?)});%'

over 1 year ago ·