Hello I still having issues with the
cache headers, just one quick question hope somebody can guide me in case I’m wrong.
My problem is simple:
I’m adding a header in my html, a simple Last-Modified: DATE-HERE.
$id = $modx->resource->get('id');
$page = $modx->getObject('modResource', $id);
$editedon = $page->get('editedon');
$strtotime = strtotime($editedon);
$editedonDate = gmdate("D, d M Y H:i:s", $strtotime) . " GMT";
I tested in an incognito window it works fine, I can see it on developer tools/network BUT
if I press F5 and refresh the page, it’s gone!
Is there a system event that is executed when the page refresh or something like that?
I mean to make the code persistent and not just go away to the underworld?
Am I doing something wrong?
Thank you very much.
After you add them, the headers are part of the original request, but reloading the page is a new request. You might look at
BTW, why not this instead of your first four lines?
$editedon = $modx->resource->get('editedon');
@bobray mate thanks for your help. 2 things:
OnHandleRequest didn’t work to set the headers on refresh
You are 100% right regarding
$editedon = $modx->resource->get('editedon'); but used with
OnHandleRequest brakes the whole site including the manager.
Thank you very much!
The event “OnHandleRequest” is invoked before the MODX code determined which resource to load for this request. Therefore
$modx->resource is not yet available in this event.
I have no experience messing with headers. If your goal is to convince the browser the page has been modified, is there any way you can add the editedon date to the URL as part of a query string?
That is what I thought
@halftrainedharry , thanks mate!
But I just have one
big doubt and I hope you can help me with this.
If you se my first post I’m running the headers on
That is working fine only on the first time the website is loaded, if you press F5 to refresh the headers from the plugin just disappear (I’m caching everything but the HTML file).
If I’m logged into the manager the headers are there all the time even after refreshing the page, so if I test them everything looks fine but once the site is testes on an incognito window or after log out from the manager no more headers after refresh.
So how can I make the headers Persistent if I’m not logged in the manager?
I can’t reproduce this.
I created the plugin with the code you posted above and tested it.
The header is always present, no matter if I’m logged in, logged out or use a private browser window.
OnLoadWebDocument should run on every (frontend) request.
If you’re logged in or not shouldn’t make a difference.
I’ll check what’s going on here, then.
Appreciate your help mate, as always!