I was trying to improve my Joomla! powered website by leveraging browser cache in .htaccess.
First, I tried this:
Code: Select all
# One month
<filesMatch ".(jpg|jpeg|png|gif|ico)$">
Header set Cache-Control "max-age=2628000, public"
</filesMatch>
Then I tried to make the browser cache the page too. So I added this piece of code to htaccess:
Code: Select all
<filesMatch ".(html|xhtml|txt|xml)$">
Header set Cache-Control "max-age=3600, public"
</filesMatch>
I realized that the J, adds an expire header in a past for every html page. Expires:Wed, 17 Aug 2005 00:00:00 GMT
I also realized that it's not only about my website, but also Joomla.org has the same expire header.
I tried many things to handle it. For example, I found the file which contains the 2005 expires header.
It's located here: public_html/libraries/joomla/application/web.php
This is it.
Code: Select all
protected function respond()
{
// Send the content-type header.
$this->setHeader('Content-Type', $this->mimeType . '; charset=' . $this->charSet);
// 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'));
}
}
$this->sendHeaders();
echo $this->getBody();
}
Code: Select all
protected function respond()
{
// Send the content-type header.
$this->setHeader('Content-Type', $this->mimeType . '; charset=' . $this->charSet);
// 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'));
}
}
$this->sendHeaders();
echo $this->getBody();
}
Code: Select all
$this->setHeader('Expires', gmdate('D, d M Y H:i:s', time() + 900) . ' GMT');
When I was happy that the problem is solved, I realized that the expires time is static and wouldn't be refreshed.
For example, If you visited the page on 00:00, the expires was for 00:15
Then, when you revisited it on 00:20, the expires was still for 00:15.
I just gave up working with it since I am not very familiar with php.
I thought some of you pro guys could help.
Regards,
Shayan.