Have been playing around with `kotlinx-html` (the ...
# kotlinx-html
p
Have been playing around with
kotlinx-html
(the JVM version) in combination with
htmx
, and liking it a lot so far. 👍 Of course typed HTML is a big advantage, but one aspect I think isn’t highlighted as much but equally as important IMHO is: much better security out of the box. Because it isn’t a simple string-based template engine, it knows when to escape input (text nodes and attributes) and reduces common risk like user injected XSS.
âś‹ 1
c
Interesting! I would agree that kotlinx.html's README could use some looove. Some more benefits, some more examples (like a
htmx
example), explaining that it's generated from w3c's HTML spec.
Do you have many pages in kotlinx-html? And do you have any idea how this impacted your compile times? We have ~300 pages and it quite heavily impacted our compile times: the v0.9 release has improved it quite a bit (as it includes some improvements that resulted from some benchmarking i did)
p
Sorry, but I have nowhere near that many pages and also re-using mainly higher-level custom tags, each in their own file. Compilation time has not really been an issue so far (this is with the Kotlin incremental compilation enabled).
c
thanks for letting me know.
of: dankjewel 🙂
m
I have done the same. A problem I encountered is that is not straightforward to generate a non-well-formed HTML snippet, containing multiple elements without a wrapping element. That is often needed with
htmx
(e.g. a list of
<option>
,
<tr>
or
<li>
). https://kotlinlang.slack.com/archives/CKWA2MV8U/p1688723457666059 Apart from that, it works fine.
p
Indeed, the current
kotlinx-html
doesn’t have support for something like
NodeList
out of the box (or at least I couldn’t find it). Have to read some of the previous threads you provided, but I assume something can be added to support this. Worst case, you can add it as a transformResponse HTMX extension.