file Improve Default Cache Plugin of Joomla 3.5

Topic Rating


01 Apr 2016 15:19 - 08 Apr 2016 17:53 #1 by Trony

  • Administrator
  • Administrator
  • Location: Roma
  • Time Zone: UTC +2:00
  • Local Time: 11:13

  • Posts: 939
  • Profile views: 3260
  • Thank you received: 8

  • Register Date: 01 Jul 2008
  • Last login: 22 Sep 2021 22:50
  • Improve Default Cache Plugin of Joomla 3.5 was created by Trony



    Joomla 3.5 with Default Cache Plugin Enabled, change Header when the pages are Cached.

    No Cached Pages: Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

    Cached Pages: Cache-Control: no-cache


    You can check your Header with Redbot .

    With this Hack, we force CMS to stay with the Default Header (Cached and No Cached Pages).

    WARNING: It's a Joomla Hack Core. BACKUP ALWAYS AND FOREVER !!!



    First Step
    Open your index.php of your template and put this code at the top
    <?php
    jimport('joomla.environment.response');
    JResponse::allowCache(true);
    $time = time()- 1;
    JResponse::setHeader('Last-Modified', gmdate('D, d M Y H:i:s', $time) . ' GMT', true);
    JResponse::setHeader('Expires', 'Wed, 17 Aug 2005 00:00:00 GMT', true);
    JResponse::setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0', false );
    JResponse::setHeader('Pragma', 'no-cache', true );
    ?>

    Second Step
    Open web.php in librariesjoomlaapplication
    and comment with // this part of the code:
    // If the response is set to uncachable, we need to set some appropriate headers so browsers don't cache the response.
    		if (!$this->response->cachable)
    		{
    			// Expires in the past.
    			//$this->setHeader('Expires', 'Wed, 17 Aug 2005 00:00:00 GMT', true);
    
    			// Always modified.
    			// $this->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT', true);
    			// $this->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', false);
    
    			// HTTP 1.0
    			$this->setHeader('Pragma', 'no-cache');
    		}
    		else
    		{
    			// Expires.
    			// $this->setHeader('Expires', gmdate('D, d M Y H:i:s', time() + 900) . ' GMT');
    
    			// Last modified.
    			if ($this->modifiedDate instanceof JDate)
    			{
    				$this->setHeader('Last-Modified', $this->modifiedDate->format('D, d M Y H:i:s'));
    			}
    		}

    Third Step
    Open page.php in librariescachecontroller
    and at the end:
    /**
    	 * Set the ETag header in the response
    	 *
    	 * @param   string  $etag  The entity tag (etag) to set
    	 *
    	 * @return  void
    	 *
    	 * @since   11.1
    	 */
    	protected function _setEtag($etag)
    	{
    	       jimport('joomla.environment.response');
                   JResponse::allowCache(true);
                   JResponse::setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0', false );
    	       JResponse::setHeader('Pragma', 'no-cache', true );
    	       $etagFuso = md5($id);
    	       JResponse::setHeader('ETag', 'W/"'.$etagFuso.'"', true );
    		
    	}
    	
    }

    Note:
    I used $etagFuso because Joomla give URL instead number.
    Weak eTag (W/) is for Compressed and Non-Compressed Gzip Pages.


    Now check with Redbot the Header of your Joomla's page.
    Music and Electronic Devices Designer. Drum and Bass Addict. Creative Mind as Lifestyle. Cat in past Life. Soccer, Ice Hockey and Snowboard Lover. Marxist.
    Sono Il Re sul Carro Danzante. Attraversando La Città Getto Via I Coriandoli Della Vostra Tristezza Regalando Passione Ed Estasi Nei Vostri Occhi.
    Follow Trony on: FusoElektronique | Facebook | Twitter | Soundcloud
    Last edit: 08 Apr 2016 17:53 by Trony.

    Please Log in or Create an account to join the conversation.

    Moderators: Trony

    You might also be interested...

    FusoElektronique - Pure Electronic Music.

    Community and Web Radio of Electronic Music since July 2008. Rome, Italy

    Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) 2021.

    About us | Our team | Cookie Policy | Privacy Policy | Terms and Conditions | Contact us | Sitemap