How are folks using OCAML with JS in practice?

What tooling are you using to use JS? Are you using a front end framework?

I used Alpine a bit with a site I was working on, and I found it very nice, but I just wrote plain Alpine JS, I didn’t do any JS emitting from OCAML. Are many people using React? Generally speaking, how are people approaching the front end?

At LexiFi we build a large client-side web app using js_of_ocaml in combination with our own GitHub - LexiFi/ocaml-vdom: Elm architecture and (V)DOM for OCaml and GitHub - LexiFi/gen_js_api: Easy OCaml bindings for Javascript libraries. For UI components themselves we mostly use Bootstrap.

Cheers,
Nicolas

3 Likes

I’m using js_of_ocaml and brr.

Always with extreme joy, but technically it depends a bit on what you mean by “front end”.

If you mean a single web page application with no server backend, for example as a cheap way to distribute simple cross-platform double-clickable “apps”, then I go with brr and note which I never really got to properly finish (app example here).

If you mean web pages backed by a web server then I use htmlit and htmlact, the latter being my own implementation of htmx (via brr of course). At that point you circumvent most need for js, not necessarily all of it, but you likely don’t need any sort of framework and a bit of brr does it (app example here).

7 Likes

besport is a social network implemented with ocsigen, a web framework that works with js_of_ocaml. It was a technical success, even if a financial failure.

ocsigen is an opinionated but full-featured web framework. There is an impressive system of typed endpoints, and the frontend and backend are written in the same file.

I haven’t used it much, but it looks to me like a very good option to write a large interactive web app from scratch.

1 Like

I’m also using js_of_ocaml and ocaml_vdom, with some further help from a CSS framework (bulma) to make things look more polished. I write my own components.

This is not less painful than any other virtual-dom based JS framework, but at least I can share the code and types with the back end. Compiling to wasm gives a very noticeable speed up, but the vdom technique still is too slow for large UIs, in my experience.

3 Likes

You are braver than I

Very helpful answers here, thanks. Much of what I’m doing is simple state management, so while alpine seems fine, it feels a little unnecessary. Js_of_ocaml looks amazing, and I don’t need to plug into any extensive front end frameworks so it seems like a great choice.

Thanks for the reminder to dig into brr, as well. That seems like a huge DX improvement for webdev

2 Likes

Ahrefs (and a few other companies) are using melange + react. See Melange Documentation Site

We are generally pretty happy with it. The react bindings are fairly solid, melange is being kept up to date with the latest ocaml, there are quite a few other good tools to complete the stack (such as styled-ppx)

1 Like