Last Updated: February 25, 2016
· 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');

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:

defined('_JEXEC') or die;
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']))
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 ·