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.
plugin OnLoadWebDocument
code:
<?php
$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";
header("Last-Modified: $editedonDate");
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!
WHY???
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?
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?
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 OnLoadWebDocument
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).
BUT…
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 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.
The event OnLoadWebDocument should run on every (frontend) request.
If you’re logged in or not shouldn’t make a difference.