Can't disable Expires and no-cache header values, bad for browser cache. OLD problem, no solution. Topic is solved

Discussion regarding Joomla! 3.x Performance issues.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
FNC
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu Jan 16, 2020 5:50 pm

Can't disable Expires and no-cache header values, bad for browser cache. OLD problem, no solution.

Post by FNC » Thu Jan 16, 2020 6:31 pm

Dear forum,

This is an old problem, still affecting Joomla 3.9.14. Pages generated by Joomla always get an Expires in 2005 header, and a pragma no-cache header. This is bad for browser speed and reverse proxy caching.

I think this is a design flaw. I've scoured the web and not found answers, only questions from other users.

There is one plugin (Expires Headers by Michael Richey) that attempts to patch this issue, and takes care of the Expires header, but after this page is cached in /cache/ on the server, it fails to have consistent headers after a page reload. Joomla simply adds no-cache to the Cache-Control header, and adds Pragma no-cache back. See example here:

Fresh load:
HTTP/1.1 200 OK
Date: Thu, 16 Jan 2020 18:26:44 GMT
Server: Apache/2.4.39 (Win64) PHP/7.4.0
X-Content-Type-Options: nosniff
X-Powered-By: PHP/7.4.0
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Expires: Thu, 16 Jan 2020 20:26:45 GMT
Cache-Control: public,max-age=7200,pre-check=7200,post-check=7200
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

Reload:
Cache-Control: public,max-age=7200,pre-check=7200,post-check=7200, no-cache
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Thu, 16 Jan 2020 18:27:22 GMT
ETag: "df76685d8a969b0adf8aa2881b6b0b88"
Expires: Thu, 16 Jan 2020 20:26:45 GMT
Keep-Alive: timeout=5, max=100
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM", CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Pragma: no-cache
Server: Apache/2.4.39 (Win64) PHP/7.4.0
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Powered-By: PHP/7.4.0

How can we fix this?

FYI:
the headers "Pragma: no-cache" and "Cache-Control: no-cache" are added by CMSApplication->toString() (CMSApplication.php:1166) because the JResponse object still has its $cachable value set to false.
It's never set to true.
This weirdly only happens after a reload from disk cache (/cache/) and not on the first request of that page.

I did more searching. The only time $this->response->cachable could ever be set to true, is through JsonDocument.php, so not ever a cms page. (ExpiresHeaders plugin does attempt to set it to true, but only during the 1st request).

 
FNC
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu Jan 16, 2020 5:50 pm

Re: Can't disable Expires and no-cache header values, bad for browser cache. OLD problem, no solution.

Post by FNC » Fri Jan 17, 2020 8:44 pm

Thank you for taking the time to reply.

I tried your modification and got a 500 error, AddOutputFilterByType is not supported by my Apache 2.4.

Once I got that sorted, I restarted Apache and my headers look exactly the same as before.

To be clear: I'm talking about headers for text/html pages, not resources such as .gif files.

hostknox . com / knowledgebase/341/How-to-improve-caching-with-modexpires.html
states the same thing: headers set in PHP override those set by .htaccess.
for example, if you have directives for caching PHP scripts in your .htaccess file, but a particular PHP script has in its instructions directives for not caching the file, it won't be cached. In short, mod_expires is typically used for caching static content.
My current solution is to install my own modified version of plugin "System - Page Cache" which I've called "System - Page Cache+". I found that here, I can set headers for server-side cached pages.

I've also tested with a simple php file of my own, setting the Cache-Control header. This behaved differently: Apache added its own headers after mine, resulting in:

Code: Select all

Cache-Control: no-cache, max-age=600
Also not what you would want.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 26429
Joined: Mon Oct 27, 2008 9:27 pm
Location: Akershus, Norway

Re: Can't disable Expires and no-cache header values, bad for browser cache. OLD problem, no solution.

Post by Per Yngve Berg » Fri Jan 17, 2020 11:00 pm

Disable the Plugin System - Page Cache. This plugin turns your site into a static site.

FNC
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu Jan 16, 2020 5:50 pm

Re: Can't disable Expires and no-cache header values, bad for browser cache. OLD problem, no solution.

Post by FNC » Fri Jan 17, 2020 11:49 pm

I just noticed that that seems to be all it does, besides one tiny thing where maybe it responds with a 304 header. The wording is very poor: "Use Browser Caching for pages"

I still need good headers though, so I started with plugin Expires Headers which needed some work - it still needs a list of exclusions like Page Cache has. Right now, the login/logout page is cached in the browser and Nginx.

I'm getting closer to getting this fixed, thanks!

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 11927
Joined: Thu Feb 15, 2007 5:48 am
Location: Suzhou, China

Re: Can't disable Expires and no-cache header values, bad for browser cache. OLD problem, no solution.

Post by toivo » Sat Jan 18, 2020 2:49 am

FNC wrote:Thank you for taking the time to reply. I tried your modification and got a 500 error
No wonder because the spammer had copied and pasted the plagiarised reply word by word from the net.
Toivo Talikka, Global Moderator

FNC
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu Jan 16, 2020 5:50 pm

Re: Can't disable Expires and no-cache header values, bad for browser cache. OLD problem, no solution.

Post by FNC » Sun Jan 19, 2020 8:46 pm

My solution consists of two parts:
  • I modified an existing Joomla plugin so that lets you
    • exclude pages with a list of regexes,
    • caching is disabled when you're logged in
    just like Joomla's broken (useless) System - Page Cache plugin.
  • I had to disable any form of server-side caching (through Global Configuration and disabling the broken plugin System - Page Cache).
The bad news is that Joomla is (was?) poorly designed with browser caching and reverse proxies in mind. This hurts a lot, if you want to optimize performance. Nginx can really break your site.

The good news is that this now works beautifully as long as you don't need a more advanced way of excluding certain pages. This would require more changes to the plugin I used.

User avatar
leolam
Joomla! Master
Joomla! Master
Posts: 19965
Joined: Mon Aug 29, 2005 10:17 am
Location: Netherlands/ UK/ S'pore/Jakarta/ North America
Contact:

Re: Can't disable Expires and no-cache header values, bad for browser cache. OLD problem, no solution.

Post by leolam » Wed Jan 22, 2020 3:46 pm

Change plugin and use JCH. The Joomla caching (not talking page cahcing since that is crap indeed) works flawless. We use on all our and client site MemcacheD on PHP7.3 with full compression without any issues. Tune and compile your server properly

Leo 8)
Joomla's #1 Professional Support Provider:
-> Joomla Professional Support: https://gws-desk.com -
-> Joomla Specialized Hosting Solutions: https://gws-host.com -
-> Joomla Webmaster Services: gws-webmaster.services

helpwithjoomla
Joomla! Intern
Joomla! Intern
Posts: 82
Joined: Sat Sep 21, 2019 7:29 pm
Contact:

Re: Can't disable Expires and no-cache header values, bad for browser cache. OLD problem, no solution.

Post by helpwithjoomla » Thu Jan 23, 2020 10:49 pm

leolam - Just curious why you don't like page caching. Can you offer more insight?
Joomla Developers Available To Help With Joomla!
https://www.helpwithjoomla.com

 

Post Reply

Return to “Performance - Joomla! 3.x”