Compile ClojureScript in Clojure into a String

I recently wrote a blog post series on different strategies for using CLJS.

The idea of embedding CLJS directly into hiccup may seem appealing, but will not scale well. It didn’t work with JS and it wouldn’t be any better CLJS. Instead you want to make functions available in the client, that you can re-use in different places, with strategies such as “grafting” to “call” them from the server generated hiccup.

There is absolutely nothing heavy about the Closure Library, unless you use like 90% of it. CLJS itself uses less than 1% so it is never a worry that this is too heavy. What is heavy is cljs.core itself, since it has to provide all the persistent datastructures and core library. It optimizes decently well, but there is always a baseline cost associated with it.

I believe it always pays off to understand what you are working with, but if you wish to skip most of it you can maybe get by with learning the often discussed HTMX library instead. I’d strongly encourage to learn CLJS and a bit of DOM instead though, even if the learning curve is substantially steeper at first. It’ll be worth it in the end, and if you already know CLJ the CLJS part isn’t that hard.