I got a requirement to be able to retrieve content from AEM repository on a web page once it is published, ie. retrieve the latest publish content.
Doing that is somehow ineffective if we have a large number of content inside the repository already.
any sorts of suggestions / best practice how to do it?
Use client side jquery ajax ($.ajax) or Apache Sling Dynamic Include or any other similar framework
Thanks for that! what will be the AJAX solutions looks like? do you have any example?
I am keen to look at the solution example if you have any with AJAX.
I don't have the details of your requirement but on a high level, you will have to create an endpoint in your aem (using servlet). These endpoint will be responsible for sending response with updated content. From front-end you will be requesting these endpoint and consume the response.
Some helpx articles you can refer to
I read your question, but I don't understand it. I understood that you want to fetch the latest published content, but the second paragraph doesn't make sense to me. Can you rephrase your question?
I agree with Joerg - your question is not clear. You want to query latest published content. What purpose is this for? Do you want to track pages that are published for reporting purposes?
the purpose is not to track pages that are being published, the purpose is to promote / display the latest published articles to users.
Thanks for the reply Joerg!
What I wanted to say on the second paragraph is basically one of the possibility to fetch the latest published content from the JCR. However it is not a really good solution (ineffective) as it is using the JS Use API which is a server-side language and potentially put a heavily load on the server.
so to summarise it, the question is basically, is there any other solutions that we can implement to fetch the latest published content so that the user can get suggestions on the latest published article once the article is published?
Yes, you can achieve it. But in this case your this particular request has to pass from dispatcher without caching.
gauravb10066713 has already mentioned few recommended approach which is used to tackle this like SDI, Ajax
OK, I think I got it.
You want to display a the list of the "last changed pages" and have that list on all pages (even the cached ones). Which means you either invalidate the complete cache on every change (not efficient), or you use an AJAX or an server-side approach like SSI/ESI to separate the rendering of this "latest changed pages" content from the rendering of the rest of the page. And maintain a single instance of this latest changed pages content and include it from the static parts (during delivery).
The recommendations by @edubey is good.
With ajax, your content fragments or components are assembled in the browser which means you need to have a really good frontend design otherwise you may see flickering when the page loads because one component's ajax response may return first than other one and things like that. This depends on your requirements, use cases & how many ajax calls you want to happen and how you manage each layer.
With SDI, you get a slight flexibility to implement with options to choose from SSI, ESI or Ajax as applicable but the design delegates to how you structure your templates and components etc.
Other aspect to keep in mind could be the entire end-to-end architecture of your site including CDN/dispatcher cache as applicable in your design/implementation.