I am learning to write simple web applications. I started with Clojure, Ring and Hiccup. I am progressing, so I believe I am not on a wrong path.
I always thought, that the goal of ClojureScript is to use the same language on the server and on the backend. But after reading tutorials and trying to become a friend of ClojureScript I have the impression, that ClojureScript cannot be mixed with Clojure.
If you have code that you want to compile for both the jvm, and for js, it is possible to use .cljc files.
I have the impression, that ClojureScript cannot be mixed with Clojure.
That’s true, although there’s a big overlap between what each supports. If a file can be run as both ClojureScript and Clojure, it’s usually given a filename which ends in .cljc.
I don’t plan to develop such big web plattforms, where the huge effort for learning all these technologies pays off
Pretty much all of the tools that are needed to compile CLJS into JS have some sensible defaults that make working with small applications as easy as creating a config file with barely any data in it (and even this step is optional) and calling a single CLI command.
Thing is, compiling CLJS into JS is not a trivial task, conceptually. It’s also slow, so if you want to embed CLJS code inside Hiccup forms, you’d have to cache the data, which already makes it all much less trivial than calling a single command to compile it all in advance.
And, while CLJS and CLJ are very similar, they have enough differences where some form can be valid in CLJS but invalid in CLJ (e.g. the #queue reader immediately comes to mind).
If you only want to create a simple web application, then I would recommend to consider using HTMX. Only reach for ClojureScript if you need to design a very interactive UI (like an image editor for example).
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.
Thanks for letting me know; that looks really useful