How to remove unwanted javascript files from joomla page.

In this short tutorial I will show you how you can remove the idle javascript files from the joomla template page, which you don’t want to use. I have described here some ways, you can choose to use the convenient one to you. Use these scripts right before the closing </head> tag.

First Code:

// this code will stop the loading of all the default joomla js files.
$this->_script = $this->_scripts = array(); 

Second Code:

         // here you will get the array which contain all the major scripts
         $document = JFactory::getDocument(); 
         $headData = $document->getHeadData();
         $scripts = $headData['scripts'];

         // here you can remove the script you want.
         $headData['scripts'] = $scripts;

Third Code:

// unset a single js file

Forth code:

// Another way to disable unwanted js.
$user =&amp; JFactory::getUser();
if($user->get('guest') == 1 || $user->get('guest') != 1) {
    $search = array('mootools', 'caption.js');
    // remove the js files
    foreach($this->_scripts as $key => $script) {
        foreach($search as $findme) {
            if(stristr($key, $findme) !== false) {






Hope, it will help someone.



Add a Comment

Your email address will not be published. Required fields are marked *


My name is Nohman Habib and I am a web developer with over 10 years of experience, programming in Joomla, Wordpress, WHMCS, vTiger and Hybrid Apps. My plan to start is to share my experience and expertise with others. Here my basic area of focus is to post tutorials primarily on Joomla development, HTML5, CSS3 and PHP.

Nohman Habib


Request a Quote

PHP Code Snippets Powered By :