Cache-Control in index.php Topic is solved

Discussion regarding Joomla! 4.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
theigloo22
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Aug 15, 2022 9:58 pm

Cache-Control in index.php

Post by theigloo22 » Thu May 18, 2023 1:35 pm

Hello :)

Is it ok to put Cache-Control at the top of index.php like this:

Code: Select all

<?php 
defined('_JEXEC') or die;
header('Cache-Control: max-age=1234567');
?>
If not, what's the best way to pass this directive in J4?

Thanks :D

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 25057
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Cache-Control in index.php

Post by pe7er » Thu May 18, 2023 2:00 pm

No, changing the Joomla core files = core hack.
Core hacks might cause issues and they can be overwritten with the next Joomla update.

It's better to add it using a plugin, template override, or do it directly at the server.
If you are using an Apache webserver then you might add it to the .htaccess file of your site.
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

theigloo22
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Aug 15, 2022 9:58 pm

Re: Cache-Control in index.php

Post by theigloo22 » Thu May 18, 2023 2:06 pm

Thanks, @pe7er

It's a custom template, so there is no problem with updates.

However, the .htaccess method sounds like the way to go.

theigloo22
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Aug 15, 2022 9:58 pm

Re: Cache-Control in index.php

Post by theigloo22 » Fri May 19, 2023 3:14 am

So now It seems I have another problem, I contacted my hosting service and asked the same question, and they said it will not work until I fix this no-cache header.

$ curl -sI https://www.xxxxx.com/ | grep cache-control
cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Does anyone know hot to fix this?

User avatar
RustyJoomla
Joomla! Explorer
Joomla! Explorer
Posts: 412
Joined: Wed Aug 01, 2007 12:08 am
Location: UK
Contact:

Re: Cache-Control in index.php

Post by RustyJoomla » Fri May 17, 2024 12:28 pm

theigloo22 wrote: Fri May 19, 2023 3:14 am So now It seems I have another problem, I contacted my hosting service and asked the same question, and they said it will not work until I fix this no-cache header.

$ curl -sI https://www.xxxxx.com/ | grep cache-control
cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Does anyone know hot to fix this?
I'm having this same issue, my headers are showing as

Code: Select all

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, no-cache, max-age=0, must-revalidate
But I can't for the life of me find where to make them change
Follow me on Twitter - http://twitter.com/RustyJoomla
Company Joomla Website - https://storm.agency

User avatar
ceford
Joomla! Hero
Joomla! Hero
Posts: 2794
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: Cache-Control in index.php

Post by ceford » Fri May 17, 2024 4:48 pm

libraries/vendor/joomla/application/src/AbstractWebApplication.php line 376

The values you see are normal. That is all I know!

User avatar
RustyJoomla
Joomla! Explorer
Joomla! Explorer
Posts: 412
Joined: Wed Aug 01, 2007 12:08 am
Location: UK
Contact:

Re: Cache-Control in index.php

Post by RustyJoomla » Mon May 20, 2024 9:37 am

Thanks for your reply.

The problem with these values is that they are essentially, overriding any caching control from the server
Follow me on Twitter - http://twitter.com/RustyJoomla
Company Joomla Website - https://storm.agency

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2990
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Cache-Control in index.php

Post by SharkyKZ » Tue May 21, 2024 6:32 am

Joomla code could be improved not to override the header if it's set in the application. Or even to separate server-side and browser caching. Until that happens, you can use PHP's native header functions to remove the header.

User avatar
RustyJoomla
Joomla! Explorer
Joomla! Explorer
Posts: 412
Joined: Wed Aug 01, 2007 12:08 am
Location: UK
Contact:

Re: Cache-Control in index.php

Post by RustyJoomla » Tue May 21, 2024 7:55 am

SharkyKZ wrote: Tue May 21, 2024 6:32 am Joomla code could be improved not to override the header if it's set in the application. Or even to separate server-side and browser caching. Until that happens, you can use PHP's native header functions to remove the header.
How can I use PHP's native header functions to remove the header?
Follow me on Twitter - http://twitter.com/RustyJoomla
Company Joomla Website - https://storm.agency


Post Reply

Return to “Performance - Joomla! 4.x”