Want to take your software engineering career to the next level? Join the mailing list for career tips & advice 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 580
Number of open issues 86
Average time to close an issue 15 days
Main language OCaml
Average time to merge a PR 9 days
Open pull requests 51+
Closed pull requests 18+
Last commit 2 months ago
Repo Created about 7 years ago
Repo Last Updated 2 months ago
Size 245 MB
Homepage http://ocsigen.or...
Organization / Authorocsigen
Latest Release3.6.0
Page Updated
Do you use js_of_ocaml? Leave a review!
View open issues (86)
View js_of_ocaml activity
View on github
Book a Mock Interview With Me (Silicon Valley Engineering Leader, 100s of interviews conducted)
Software engineers: It's time to get promoted. Starting NOW! Subscribe to my mailing list and I will equip you with tools, tips and actionable advice to grow in your career.
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.


See opam file for version constraints.


Toplevel requirements

  • 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-compiler js_of_ocaml-ppx


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 cubes.ml

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) are not supported in general. However,

  • Bigarray: bigarrays are supported using Typed Arrays
  • Num: supported
  • Str: supported
  • Graphics: partially supported using canvas (see js_of_ocaml-lwt.graphics)
  • 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
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)
  • almost 4 years Build system does not recompile executables when code in compiler/lib changes
  • almost 4 years Use .exe extension when using native Windows ports
  • almost 4 years Cannot disable findlib support
  • almost 4 years README does not mention dependency on Yojson
  • almost 4 years Evaluation ocaml code in the browser
  • almost 4 years Possible wrong code generated with Js.Optdef.map and localStorage
  • about 4 years `make -C tests` fails
  • about 4 years Svg elements or not compatible with eventTarget
  • about 4 years Discussion: raise exception and catch exception
  • about 4 years escape vs encodeURIComponent
  • about 4 years ES6 Support
  • about 4 years Labelled arguments
  • about 4 years large memory usage on 4.03.0 compilation
  • about 4 years suggestion: use `#=` instead of `:=` for js property set
  • about 4 years `Json.unsafe_input` and MlStrings
  • over 4 years Better runtime support for nodejs
  • over 4 years [syntax] ideas: having `#?` property ready
  • over 4 years Why are window##.{inner,outer}{Width,Height} optdef?
  • over 4 years Add selection* attributes to appropriate input elements
  • over 4 years XmlHTTPRequest and POST requests to send raw data
  • over 4 years Run tests from the ocaml compiler testsuite
  • over 4 years Stdio not handled well
  • about 5 years Distribute the ocamlbuild plugin separately
  • about 5 years Marshaling loops on cyclic values
  • about 5 years Better inlining ?
  • about 5 years Implement jsoo constructor deriver.
  • about 5 years did js_of_ocaml try to explore google closure compiler advanced mode?
  • over 5 years indexedDB API
  • over 5 years The values of mouse_x and mouse_y in Graphics_js.status are not correct on Chrome
  • over 5 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]son.cm* 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: https://www.ecma-international.org/ecma-402…
  • WIP: Port all PPX's to ppxlib
  • Upgrade to ocamlformat 0.15.0
  • Tests: update tests with OCaml 4.11
  • Eliminate allocation of dummy function
  • OCaml 4.11 support
  • Runtime: specialize caml_call_gen
  • Compiler: parse standard runtime at compile time
  • Compiler: cleanup usage of IString (now NativeString) vs String
  • recognize String concat
  • Use javascript string by default
  • Revert to dune.1
  • Random set of patches on the compiler (WIP)
  • Compiler: specialized null (WIP)
  • [WIP] add Promise API
  • Post process doc to integrate into ocsigen.org (WIP)
  • Fix ppx_deriving_json with nested polymorphic variant
  • Let all SVG elements respond to "global event attributes." (part 2)
  • Alternative interface for jsooTop
  • Introduce a distinction between blocks and arrays
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


  • Compiler: change compilation scheme for branches (#948)
  • Compiler: Introduce sub-command: link, build-runtime, build-fs (#987)
  • Compiler: embed javascript runtime in the compiler (#978)
  • Compiler: refactor javascript lexer/parser, add tests (#986)
  • Runtime: clean runtime for string vs bytes
  • Runtime: remove many old polyfill
  • Runtime: add unix_isatty
  • Runtime: optimize caml_call_gen (#996)
  • Runtime: change representation of int64 (#905)
  • Runtime: improve node.js backend for Sys.command (#979)
  • Runtime: add javascript runtime for Str (#998)
  • Lib: add closest method to element (#930)
  • Lib: add several methods and functions to Typed_array (#970)
  • Ppx: ppx_js behave better with merlin (#933)
  • Misc: Cleanup Meta files (e.g. js_of_ocaml.tyxml is no longer valid library name)
  • Misc: switch to ocamlformat.0.14

Bug fixes

  • Compiler: fix vardecl optim (#946)
  • Compiler: restore optimization when generating if statements
  • Compiler: fix javascript parser in the presence of line directives (#980)
  • Runtime: Catch nodejs errors and re-raise them as Sys_error
  • Runtime: fix caml_parse_sign_and_base and unsigned syntax
  • Runtime: fix caml_js_wrap_meth_callback_strict (#996)
  • Runtime: fix over-application of javascript callback (#996)
  • Runtime: fix partial-application of javascript callback (#996)
  • Runtime: fic caml_js_wrap_meth_callback_unsafe (#996)
  • Lib: Fix the type of blur and focus event to be focusEvent (#929)



  • Misc: support for ocaml 4.10
  • Misc: ppx_deriving_json uses ppxlib >= 0.9

Bug fixes

  • Runtime: fix pseudo fs initialization (#931)



Bug fixes

  • Runtime: fix poly compare with null and undefined (#920)
  • Lib: Deriving Json does not export an [import] unit
  • Dynlink/toplevel: export all units when no export file is specified (#921)
  • Ppx: ppx_deriving_json should allow [%to_json: t] syntax
Other projects in OCaml
Powered by Autocode - Instant Webhooks, Scripts and APIs
Autocode logo wordmark