https://kotlinlang.org logo
Title
a

arthur_sav

11/16/2020, 6:10 PM
What’s your favourite Ktor + Frontend setup? Started with simple HTML/JS + Freemarker but it’s getting messy.
c

Casey Brooks

11/16/2020, 6:17 PM
I’ve found that I don’t like using server-side rendered template engines mixed with frontend Kotlin/JS. I’ve found Kotlin/JS to “feel” the best when using it as a completely separate frontend app talking to the server purely over REST APIs (or to a lesser degree, websockets)
a

arthur_sav

11/16/2020, 6:29 PM
So it’s not just me. Leaning towards a separate ReactJS frontend that talks to Ktor via REST. Was hoping to somehow avoid JS but i guess we’re not there yet.
c

Casey Brooks

11/16/2020, 6:31 PM
Alpine is an interesting approach that should place nicely with server-side rendering. Just add the script tag and everything else is just markup on normal HTML https://github.com/alpinejs/alpine
But overall, I’ve done a lot with SSR and I’ve generally found that it doesn’t make for a very great or polished front-end UX. It works, and for fast development, internal projects, or mostly-static content, it’s probably good enough. But to really get a snappy, responsive experience on the frontend, having some kind of decoupled client-rendered UI does feel better from a user’s perspective. Also makes it easier to integrate into a mobile app if you ever need to add that, as it would be talking to the same APIs that the web client uses
a

arthur_sav

11/16/2020, 6:44 PM
Yeah depends on usage. My use case is more of an actual app, with user interactions / api calls / update parts of UI. Was looking into KotlinJS wrappers but it’s still pretty new.
c

Casey Brooks

11/16/2020, 6:52 PM
I’ve mostly been playing around with a pure-kotlin reactive approach based on Flow and kotlinx HTML, and am very pleased with it so far. Given how large the bundle is with kotlin alone, I’d like to avoid huge non-kotlin dependencies since Kotlin offers pretty much all i’d need anyway
In particular, the workaround in this issue (https://github.com/Kotlin/kotlinx.html/issues/88) makes it possible to get the underlying HTMLElement from any point in the kotlinx HTML DSL, so you can mount dynamic content to that one element and update it later with new content from a Flow, and not necessarily replace the entire screen on every small data change
a

arthur_sav

11/16/2020, 7:40 PM
I’d hate to base my app on a hack 😁 specially if it’s not a toy project.
h

holgerbrandl

11/16/2020, 9:09 PM
For simple web apps thymeleaf works great and has good ide support.
👍 1