- Home
- Code Transpilers
- js_of_ocaml
js_of_ocaml
What it is
js_of_ocaml compiles OCaml bytecode programs into JavaScript for use in browsers and Node.js. It works with an existing OCaml installation, so libraries do not need to be recompiled. Dune supports it directly, using separate compilation during development and whole-program compilation for release builds. Release compilation can remove unused code across the program and optimize between modules. The library provides a typed way to connect OCaml and JavaScript values, with PPX syntax for JavaScript properties, methods, constructors, and objects. Browser bindings cover APIs including the DOM, Fetch, WebSockets, WebGL, workers, and typed arrays. Optional packages provide Lwt support, TyXML, JSON derivation, and an OCaml toplevel in the browser. Generated code is documented for Node.js 18 or later, QuickJS-NG, and modern ES2020 browsers. The compiler is free and open source, with installation through opam. Documented requirements include OCaml 4.13 to 5.5, Dune 3.20 or later, and Menhir.
For and against
For
- Uses existing OCaml libraries without recompiling them
- Dune supports development and release compilation
- Typed OCaml and JavaScript interoperability
- Includes bindings for many browser APIs
- Free and open source
Against
- Most of the Sys module is unsupported
- Thread and other extra libraries are generally unsupported
- Tail calls are not optimized in general
The verdict
js_of_ocaml offers OCaml developers a path to browser and Node.js runtimes, with Dune integration and browser API bindings. Check its library and tail-call limitations against your program before adopting it.
Who it suits
It suits OCaml developers who want to run existing bytecode programs in browsers or Node.js and connect them to JavaScript or browser APIs. Users should be comfortable with its documented OCaml, Dune, and Menhir requirements.
Plans and prices
js_of_ocaml
No paid plans or usage limits stated on the pages reviewed
Read 9 Oct 2026 · github.com
On the record
- Async integration
- The optional js_of_ocaml-lwt package provides Lwt support and bindings including DOM events, XMLHttpRequest, and JavaScript promises.ocsigen.org · read 9 Oct 2026
- Browser APIs
- The base library includes bindings for browser APIs such as DOM, Fetch, WebSockets, WebGL, workers, and typed arrays.ocsigen.org · read 9 Oct 2026
- Browser bindings
- The project includes bindings for a large part of browser APIs.ocsigen.org · read 9 Oct 2026
- Browser support
- Generated JavaScript supports modern browsers that implement ECMAScript 2020, including Chrome 80+, Firefox 74+, Safari 13.4+, and Edge 80+.ocsigen.org · read 9 Oct 2026
- Build integration
- Dune supports js_of_ocaml natively and selects separate compilation in dev and whole-program compilation in release builds.ocsigen.org · read 9 Oct 2026
- Installation
- The compiler and related packages are installable through opam, the OCaml package manager.ocsigen.org · read 9 Oct 2026
- JavaScript interop
- Its library provides a typed interface for bridging differences between OCaml and JavaScript values.ocsigen.org · read 9 Oct 2026
- JavaScript interoperability
- The library provides a typed interface for bridging OCaml and JavaScript values, with PPX syntax for JavaScript properties, methods, constructors, and objects.ocsigen.org · read 9 Oct 2026
- Libraries
- The distribution includes packages for Lwt support, TyXML, JSON derivation, and running an OCaml toplevel in the browser.ocsigen.org · read 9 Oct 2026
- License
- The repository lists GPL-2.0-or-later and LGPL-2.1-or-later with the OCaml linking exception as its licenses.github.com · read 9 Oct 2026
- Limits
- Most of the Sys module is unsupported, extra OCaml libraries such as Thread are generally unsupported, and tail calls are not optimized in general.ocsigen.org · read 9 Oct 2026
- Node support
- The installation guide lists Node.js 18 or later as a supported environment.ocsigen.org · read 9 Oct 2026
- No recompiling libraries
- It works with an existing OCaml installation and does not require recompiling libraries.ocsigen.org · read 9 Oct 2026
- Optimization
- Whole-program compilation performs global dead-code elimination and cross-module optimizations to produce smaller and faster output.ocsigen.org · read 9 Oct 2026
- Performance
- The project says its benchmarks show generated programs typically run faster than with the OCaml bytecode interpreter.ocsigen.org · read 9 Oct 2026
- Purpose
- js_of_ocaml compiles OCaml bytecode programs to JavaScript for use in browsers and Node.js.ocsigen.org · read 9 Oct 2026
- Requirements
- The documented compiler requirements include OCaml 4.13 to 5.5, Dune 3.20 or later, and Menhir.ocsigen.org · read 9 Oct 2026
- Runtime targets
- Generated JavaScript is documented to work with Node.js 18 or later, modern ES2020 browsers, and QuickJS-NG.ocsigen.org · read 9 Oct 2026