Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


Compiler from OCaml to Javascript.

Subscribe to updates I use js_of_ocaml

Statistics on js_of_ocaml

Number of watchers on Github 395
Number of open issues 48
Average time to close an issue 18 days
Main language OCaml
Average time to merge a PR 9 days
Open pull requests 32+
Closed pull requests 10+
Last commit about 2 years ago
Repo Created over 6 years ago
Repo Last Updated almost 2 years ago
Size 114 MB
Homepage http://ocsigen.or...
Organization / Authorocsigen
Latest Release3.0.0
Page Updated
Do you use js_of_ocaml? Leave a review!
View open issues (48)
View js_of_ocaml activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating js_of_ocaml for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Build Status

Js_of_ocaml (jsoo)

Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js.

  • It is easy to install and use as it works with an existing installation of OCaml, with no need to recompile any library.
  • It comes with bindings for a large part of the browser APIs.
  • According to our benchmarks, the generated programs runs typically faster than with the OCaml bytecode interpreter.
  • We believe this compiler will prove much easier to maintain than a retargeted OCaml compiler, as the bytecode provides a very stable API.


Findlib, cppo See opam file for version constraints.


Toplevel requirements

  • base64, tyxml, reactiveData
  • ocp-indent: needed to support indentation in the toplevel
  • higlo: needed to support Syntax highlighting in the toplevel
  • cohttp: needed to build the toplevel webserver



opam install js_of_ocaml js_of_ocaml-ppx


  • edit Makefile.conf to change the default configuration
  • run make all to compile
  • run make install as root to install the compiler and its libraries
  • run make uninstall as root to uninstall them

You can run make toplevel-examples if you want to build a Web-based OCaml toplevel as well. Try the toplevel


Your program must first be compiled using the OCaml bytecode compiler ocamlc. JavaScript bindings are provided by the js_of_ocaml package. The syntax extension is provided by js_of_ocaml.syntax package.

ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.ppx -linkpkg -o cubes.byte

Then, run the js_of_ocaml compiler to produce JavaScript code:

js_of_ocaml cubes.byte


Most of the OCaml standard library is supported. However,

  • Weak semantic cannot be implemented using JavaScript. A dummy implementation is provided.
  • Most of the Sys module is not supported.

Extra libraries distributed with Ocaml (such as Thread or Str) are not supported in general. However,

  • Bigarray: bigarrays are supported using Typed Arrays
  • Num: supported using +nat.js option
  • Graphics: partially supported using canvas (see
  • Unix: time related functions are supported

Tail call is not optimized in general. However, mutually recursive functions are optimized:

  • self recursive functions (when the tail calls are the function itself) are compiled using a loop.
  • trampolines are used otherwise. More about tail call optimization.

Data representation differs from the usual one. Most notably, integers are 32 bits (rather than 31 bits or 63 bits), which is their natural size in JavaScript, and floats are not boxed. As a consequence, marshalling, polymorphic comparison, and hashing functions can yield results different from usual:

  • marshalling of floats is not supported (unmarshalling works);
  • the polymorphic hash function will not give the same results on datastructures containing floats;
  • these functions may be more prone to stack overflow.


Contents of the distribution

Filename Description
LICENSE license and copyright notice
README this file
compiler/ compiler
examples/ small examples
lib/ library for interfacing with JavaScript APIs
ppx/ ppx syntax extensions
camlp4/ camlp4 syntax extensions
runtime/ runtime system
toplevel/ web-based OCaml toplevel
ocamlbuild/ ocamlbuild plugin for js_of_ocaml
js_of_ocaml open issues Ask a question     (View All Issues)
  • over 3 years Build system does not recompile executables when code in compiler/lib changes
  • over 3 years Use .exe extension when using native Windows ports
  • over 3 years Cannot disable findlib support
  • over 3 years README does not mention dependency on Yojson
  • over 3 years Evaluation ocaml code in the browser
  • over 3 years Possible wrong code generated with and localStorage
  • over 3 years `make -C tests` fails
  • over 3 years Svg elements or not compatible with eventTarget
  • over 3 years Discussion: raise exception and catch exception
  • over 3 years escape vs encodeURIComponent
  • over 3 years ES6 Support
  • over 3 years Labelled arguments
  • over 3 years large memory usage on 4.03.0 compilation
  • over 3 years suggestion: use `#=` instead of `:=` for js property set
  • over 3 years `Json.unsafe_input` and MlStrings
  • over 3 years Better runtime support for nodejs
  • almost 4 years [syntax] ideas: having `#?` property ready
  • almost 4 years Why are window##.{inner,outer}{Width,Height} optdef?
  • almost 4 years Add selection* attributes to appropriate input elements
  • about 4 years XmlHTTPRequest and POST requests to send raw data
  • about 4 years Run tests from the ocaml compiler testsuite
  • about 4 years Stdio not handled well
  • over 4 years Distribute the ocamlbuild plugin separately
  • over 4 years Marshaling loops on cyclic values
  • over 4 years Better inlining ?
  • over 4 years Implement jsoo constructor deriver.
  • over 4 years did js_of_ocaml try to explore google closure compiler advanced mode?
  • over 4 years indexedDB API
  • over 4 years The values of mouse_x and mouse_y in Graphics_js.status are not correct on Chrome
  • over 4 years fix nat.js
js_of_ocaml open pull requests (View All Pulls)
  • add origin method to Dom_html.location
  • store/access javascript error (with backtrace) within ocaml exceptions.
  • Add Tyxml_js.register
  • XmlHttpRequest: API change for perform functions.
  • Initial support for async (WIP)
  • Switch to ocamlbuild (and topkg)
  • Switch to OASIS
  • Prevent inlining to loop on a block that immediately branches to itself
  • Fix `Js.string` for deserialized strings
  • Added Lwt_js_events.{aborts,errors,loads}.
  • Alternative interface for JsooTop.
  • Dom_html: Add selection attributes to textarea.
  • Compat with Tyxml 4.0
  • Small changes wrt compiler-libs.
  • Dom_html: add crossorigin to linkElement.
  • Add is_null function
  • Build deriving_[Jj]* even without deriving package
  • (wip) Import new ppx scheme from let-def
  • fixed a typo
  • Export: echo --> cat
  • (WIP)
  • windo##open_ returns possibly null value
  • Split js_of_ocaml (WIP)
  • 2.8.4
  • rework version handling
  • Lib: split js_of_ocaml-core (EXPERIMENT)
  • Change type of Dom_html.storageEvent
  • Compiler: support for OCaml GPR#1568
  • Build: wrap js_of_ocaml lib
  • Add progressive web app support
  • Compiler: improve arity approximation
  • Internationalization API:…
js_of_ocaml questions on Stackoverflow (View All Questions)
  • How to use properly compile OCaml programs with js_of_ocaml?
  • Meaning of # character in front of js_of_ocaml dom types
  • A canvas with a horizontal scroll bar in js_of_ocaml
  • How can I add a onclick method using js_of_ocaml?
  • Js_of_ocaml - Error when get cookie
  • Js_of_ocaml : missing primitive when calling ocurl and str
  • How to call a js_of_ocaml method?
  • How to construct a js object and call its methods with js_of_ocaml?
  • js_of_ocaml and Deriving_Json
  • How to use modules with js_of_ocaml?
  • js_of_ocaml and Core
  • Can js_of_ocaml compile in-memory data-structures from the OCaml compiler?
  • js_of_ocaml and event_listener
  • Code completion not working with OcaIde + js_of_ocaml
  • Code completion not working for js_of_ocaml in typerex
  • Marshal and magic_copy in js_of_ocaml
js_of_ocaml list of languages used
js_of_ocaml latest release notes
3.0.0 Js_of_ocaml version 3.0.0

Version 3.0.0


  • Misc: switch to ppx instead of camlp4
  • Misc: always install deriving_json
  • Misc: remove support for async_kernel, bin_prot
  • Misc: remove support for ppx_driver
  • Misc: split js_of_ocaml in multiple packages
  • Misc: switch to jbuilder
  • Misc: new pseudo filesystem support with better node support
  • Compiler: sourcemap support is now optional
  • Compiler: no more strong dep on yojson, b64, menhir, ocamllex
  • Compiler: improve separate compilation workflow
  • Runtime: add support for weakdef
  • Syntaxes: add expect tests
  • Syntaxes: switch to ocaml-migrate-parsetree and ppx_tools_versioned
  • Lib: Add primitives in [Js.Unsafe]
  • Lib: remove keycode module, replaced by Dom_html.Keyboard_code
  • Lib: XmlHttpRequest, API change for perform functions.

Bug fixes:

  • Runtime: fix many stubs
  • Lib: fix many signatures
  • Compiler: fix performance of compilation passes (simpl,clean)
  • Compiler: fix compat with OCaml 4.06
  • Toplevel: flush channels after execution.
  • Toplevel: fix toplevel generation when using -export-unit
2.8.3 Js_of_ocaml version 2.8.3
2.8.2 Js_of_ocaml version 2.8.2
Other projects in OCaml