Improve Default Cache Plugin of Joomla 3.5

More
01 Apr 2016 17:19 - 22 Aug 2026 00:01 #4227 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

Code:
<?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:

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:

Code:
/** * 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.

Do You ❤️ It?!? Buy Me a Coffee! Thank You in advance... ✌️


Support me on Ko-fi

"Music and Electronic Devices Designer. Drum and Bass Addict. Creative Mind as Lifestyle. Cat in past Life. Football, 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.

😼 This-Ads-Feeds-My-Cats