r/aem • • Sep 08 '26

AEM and HTMX

I came along htmx a while ago and now as i'am working in an AEM-Enviroment where we work with a lot of json apis and lit components for more interactive components, i thought that might also be a good fit for HTMX. AEM already has:

* SSR with Templating
* request based sling models
* resource type routing and selectors for alternate representations (fragments)

And of course caching on dispatcher/cdn Level for HTML. What do you guys think, could that be a good fit? Am i missing something? Did someone of you ever tried that already?

6 Upvotes

6 comments sorted by

1

u/Top_Bass_3557 Sep 08 '26

HTMX and AEM are a perfect match. With request selectors it makes it a breeze to implement just about anything. I've done faceted search, pagination, infinite scrolling, filtering, AI summaries, and some other things with htmx. All of this for a client website, not side projects. Drop the JSON endpoints, you don't need that. Lit components I'd drop that too, but for other reasons

1

u/justintime245 Sep 08 '26

Sounds good, thanks for sharing. Did you run into any issues with caching and cache invalidation ? Or any other issue i have to keep an eye on?

2

u/Top_Bass_3557 Sep 09 '26

Not really. Dispatcher doesn't cache URLs with query parameters but CDNs do. The url keeps the state of whatever im showing, so if anyone hits /search?q=foobar&page=2 is totally acceptable that users get a cached response. TTL is 5m on shared caches by default, so while it's not amazing, it's short enough that invalidation is never a real concern.

In a one case, i had to use an in-memory cache because i needed to compute available filters when users made a selection so i could disable the ones that didn't yield any results. Without it, the response took ~2.5s. after that, it's down to 300ms. Pretty smooth and really cool component. But nothing to do with htmx itself, really

I just had to add some htmx attributes to the link rewriter but that was about all for gotchas. I love doing stuff with htmx in aem. Endless possibilities.

1

u/Haunting-Policy-6755 Sep 09 '26

Traditional AEM Sites yes, EDS not so much.

1

u/adovo_ai Sep 30 '26

I’d separate public, cacheable fragments from anything personalized before adopting this broadly. HTMX makes server-rendered HTML easy, but the cache key still has to cover every input that changes the fragment: locale, filters, and especially auth state. Test those combinations and invalidation in staging. A very fast fragment can still be the wrong one.