Joomla expires header bug. Expired in the past 2005 !

Did you find a bug in Joomla! 3.x but aren't sure? This forum is the place to help figure out if the problem is a bug and how to report it. If you are an experienced Joomla! user and are certain that you have found a bug please use the Bug Tracker to submit your issue.
This forum is for discussion about bugs and to get help with reporting them to the Bug Tracker: https://issues.joomla.org

Moderator: ooffick

Forum rules
Please use the official Bug Tracker to report a bug: https://issues.joomla.org
Post Reply
shiml
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Wed Jan 06, 2016 9:38 pm

Joomla expires header bug. Expired in the past 2005 !

Post by shiml » Mon Jul 18, 2016 1:23 pm

Hey people.

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>
Which managed to make the image files to be stored in the browser's cache.

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 was expecting the html pages to be stored in browsers cache for one hour. But guess what happened.

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();
	}
I tried this one instead:

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();
	}
The last one did work for the first time. I mean when I visited my website after I made the changes, The expires header was pointing to 15 mins later ( as was expected from

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.

mbabker
Joomla! Hero
Joomla! Hero
Posts: 2176
Joined: Sun Feb 28, 2010 8:26 pm

Re: Joomla expires header bug. Expired in the past 2005 !

Post by mbabker » Mon Jul 18, 2016 2:26 pm

The 2005 header is only if the page is set to not be cached to tell browsers to not cache it. The fact that header is being sent tells me something is telling the application class to not allow the request to be cached, which sounds like isn't what you're expecting. So you'd need to find out what's causing that.

Note that Joomla's core extensions by default pretty much disable caching for authenticated users, so if you're testing in this manner, you'll want to test instead with a guest user.
So long and thanks for all the fish.

Manually updating Joomla? See https://gist.github.com/mbabker/d7bfb4e ... 3607f89281

shiml
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Wed Jan 06, 2016 9:38 pm

Re: Joomla expires header bug. Expired in the past 2005 !

Post by shiml » Mon Jul 18, 2016 3:06 pm

mbabker wrote:The 2005 header is only if the page is set to not be cached to tell browsers to not cache it. The fact that header is being sent tells me something is telling the application class to not allow the request to be cached, which sounds like isn't what you're expecting. So you'd need to find out what's causing that.

Note that Joomla's core extensions by default pretty much disable caching for authenticated users, so if you're testing in this manner, you'll want to test instead with a guest user.
Hello sir. I understand that that expires header for 2005 means not to cache the page. But why?
Seems like Joomla is doing it in a bad way.

I am testing as guest and as I mentioned before, even joomla.org has the same issue. Which means it doesn't even allow caching for the guests.

I also tried joomla plugin called "System - Page Cache". Enabling or disabling it makes no difference. Neither does turning on the "Use Browser Caching" in the plugin settings.

I think something is wrong with the page caching of Joomla 3.6 !

mbabker
Joomla! Hero
Joomla! Hero
Posts: 2176
Joined: Sun Feb 28, 2010 8:26 pm

Re: Joomla expires header bug. Expired in the past 2005 !

Post by mbabker » Mon Jul 18, 2016 6:12 pm

Just as you found, there's a check in the application class that determines whether caching is set or not and depending on that condition sends headers to either cache the page or not cache it.

Joomla's caching is interesting to say the least. For example, joomla.org itself does have Joomla's conservative caching enabled which caches some internal data lookups and the output of components and modules, but it doesn't set a flag to the application class to enable browser caching. Actually, on a quick search I can't find anything that's actually turning that on in core.

The page cache plugin is another caching mechanism separate from the global caching system. With that enabled, the full page request will get cached server side and served back if possible.

So, long and short of it is that the caching configurations affect the server side cache, but at the moment it appears Joomla isn't doing anything to give client side (browser) caching instructions.
So long and thanks for all the fish.

Manually updating Joomla? See https://gist.github.com/mbabker/d7bfb4e ... 3607f89281

shiml
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Wed Jan 06, 2016 9:38 pm

Re: Joomla expires header bug. Expired in the past 2005 !

Post by shiml » Mon Jul 18, 2016 7:43 pm

Ok.

So, how can I configure page caching?

The only things I think of is:

1- <filesMatch ".(html|xhtml|txt|xml)$">
Header set Cache-Control "max-age=3600, public"
</filesMatch>

2- System - Page Cache > Use browser caching: On

Is there any mechanism that makes page caching possible?

tomholl
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Mon Mar 21, 2011 4:42 pm

Re: Joomla expires header bug. Expired in the past 2005 !

Post by tomholl » Tue Mar 27, 2018 12:09 am

Hello @shiml and @mbabker,

A couple of days ago, I posted a question regarding the default Joomla http header that includes the "Expires:Wed, 17 Aug 2005 00:00:00 GMT" directive.

Pls view: viewtopic.php?f=706&t=960458

My question about the default header is the following.
It appears that the "Expires in the past" directive no longer works. It appears, browsers do cache in the html of my website despite of the Joomla http header, which was meant to ensure, that the html of the website is not cached in by the browsers. I wonder if the reason why the header doesn't work is because their is typically a modification date included in the header that is a later date than the expiry date.
The bottom line is that it appears, with the current default http response, I don't have control over which version of my website loads to the browser of my website visitors.

Following is a typical default Joomla http header.

###
Date: Mon, 26 Mar 2018 19:19:59 GMT
Server: Apache/2.4.23 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4 mod_fcgid/2.3.9
X-Powered-By: PHP/7.0.28
X-Logged-In: False
X-Content-Powered-By: K2 v2.8.0 (by JoomlaWorks)
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Expires: Wed, 17 Aug 2005 00:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: 1ea22306f7287924a5540d1ccf0163bb=n7v1fgq8qovq4ahca7flufbig6; path=/; HttpOnly
X-Frame-Options: SAMEORIGIN
Last-Modified: Mon, 26 Mar 2018 19:20:00 GMT
Vary: Accept-Encoding,User-Agent
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-transform
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
###

Please advise how to address this problem.

PS.: I also raised an issue on the https://github.com/joomla/joomla-websites/issues/1144 -- I am not sure which forum is more appropriate for seeking a solution for this question.

User avatar
brian
Joomla! Master
Joomla! Master
Posts: 11715
Joined: Fri Aug 12, 2005 7:19 am
Location: Leeds, UK
Contact:

Re: Joomla expires header bug. Expired in the past 2005 !

Post by brian » Mon Jun 25, 2018 7:52 am

https://developer.mozilla.org/en-US/doc ... rs/Expires

If there is a Cache-Control header with the "max-age" or "s-maxage" directive in the response, the Expires header is ignored.
"Exploited yesterday... Hacked tomorrow"
Blog http://brian.teeman.net/
Joomla Hidden Secrets http://hiddenjoomlasecrets.com/


Post Reply

Return to “Joomla! 3.x Bug Reporting”