Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by

Hi,

I wanted to find out whether it's possible to have a clojure web application that is serving html and use clojurescript to directly manipulate DOM elements.

All the setups I've encountered usually involve a Single Page Application written in clojurescript on the frontend and clojure on the backend.

I would like a traditional setup, a multipage web application.

I checked out shadow-cljs and it seems to follow the single page setup where it serves the HTML itself. What if I am generating the HTML myself?

Is it possible to achieve such a set-up? Also is it possible to do it with hot reloading?

Thank you for answering my question.

2 Answers

0 votes
by

It is possible, even with shadow-cljs - it doesn't preclude you in any way. During development you can use its bulit-in server to serve multiple HTML pages, but you don't have you - can you can just as easily use your own server.

Hot reloading will work just fine because shadow-cljs will still have its own server, although it will serve only code updates and not HTML pages.

by
Thank you for your answer. I have several more questions. Will I still need to use :target :browser or is there a special target? Also will I need to run the main repl for clojure and a separate one for shadow-cljs? Also is it possible to refresh or reload everything when I change code in the clojurescript side?
by
Same `:browser` target. There might be multiple builds if you prefer to have a separate script for each page, but then I'd also suggest looking into module splitting so you don't have to ship compiled libraries, including CLJS itself, with every page.

Regarding REPL - there's no need to run any REPL at all. I almost never use CLJS REPLs and almost always use a CLJ REPL, and shadow-cljs stays as a completely separate process that I just launch manually via its CLI.

If by "refresh or reload everything" you mean reloading the whole page as opposed to the built-in CLJS hot code reload - I think so, yes. Shadow-cljs has build hooks, you can reload the page via CLJS code in the `:after-load` hook.
by
edited by
Thank you. I have more clarity on what I need to do. It seems very possible. Thanks!

If I do it like this will I miss the repl driven development in the clojurescript side?
...