Hi,
Has anyone noticed that page.lastModified doesn't always update when you publish a page? How do you reliably get the actual "last published" timestamp of a page?
Not looking for jcr:lastModified or cq:lastReplicationAction - they’re not always reliable for personalization logic.
Hi @MatthewDa19,
I think, the only reliable way is to use the cq:lastReplicated
property from the cq:Page
node (not the jcr:content node). It updates only on successful publish and remains untouched by mere edits or autosaves. Works well for showing "last updated" timestamps to end users.
This works because:
Most devs assume jcr:lastModified
or cq:lastModified
gives the latest update.
Few realize cq:lastReplicated
exists on the page node, not jcr:content
.
The question seems simple, but the nuance makes it expert-level.
Hope that helps!
This does not work, the cq:page nodetype is pretty much locked down what additional properties you can add to it. cq:lastReplicated is always set on the jcr:content node.
(Plus: on a publish instance it is not reliable, because this property is only set on author after the replication has completed. That means when you publish a page twice cq:lastReplicated on publish shows the date of the first replication.)
you can say page.lastModified Misleads
The page.lastModified API in AEM Core WCM Components (and Page.getLastModified() in Sling) often affected by:
cq:lastReplicated is the best choice for displaying the last replicated timestamp; it shows you the timestamp of the last successful replication action on the node it exists on. Making sure you have fallback code in place of course.
I had a scenario back in the past where we had blog articles which we wish to display the "authored date". For these dates, we decided to add in a new page property called author date, so there are no side effects while authoring pages with the right date.
To reliably get the actual "last published" timestamp of a page in AEM, use:
Path: /content/your-page/jcr:content/cq:lastReplicated
Type: Date
Set on: Successful publish
Reliable: Yes — updated only on successful replication
Avoid jcr:lastModified and cq:lastReplicationAction as they can be misleading.
Hi @MatthewDa19 ,
Use cq:lastReplicated
Property: cq:lastReplicated
- Type: Date
- Location: On the page node itself, e.g., /content/mysite/page
- Not on: /content/mysite/page/jcr:content
This property is updated only when the page is successfully published to the publish instance, and it remains untouched by any author-side changes or autosaves.
Regards,
Amit
Views
Likes
Replies
Views
Like
Replies