Tarides Logo
A 3D rendering of a semi transparent browser window with 'www.' in the address bar and '</>' displayed in the middle of the window.

OCaml Web Development: Essential Tools and Libraries in 2025

Isabella Leandersson

Communications Officer

Xavier Van de Woestyne

Senior Software Engineer

Posted on Thu, 15 May 2025

Should you use OCaml for web projects? Web development trends are a hotly debated topic in the computer programming world and the familiar faces of languages and frameworks are unlikely to change: hypertext markup language or HTML, CSS, and JavaScript are the core technologies (with server-side technologies such as PHP, Python, etc.), and React, Vue, Svelte, and Angular are proving to be as popular as ever. AI and machine learning might be the biggest foreseeable changes to the industry, driving the emergence of new tools and workflows. But there is something else gaining momentum in the world of web development: functional programming!

Functional programming fits in well with the web world. The transactional nature of HTTP and the convergence towards immutable state management solutions (such as Redux and consort) make OCaml a very good candidate for web application development. In this article, we give you an overview of some of the web solutions supported by the OCaml ecosystem. It's important to note that we can't include every single one of the web development libraries available for OCaml, as there are simply too many for one post!

Functional Programming, OCaml, and the Web

Why do some developers use functional programming for web development? Functional programs leverage concepts like immutability, higher-order functions, and formal verification to achieve, among other beneficial outcomes, better code reusability, parallelism, and fewer bugs. These developer-friendly qualities that simplify programming and increase productivity are behind the rising interest in FP for front- and backend web development.

As a functional programming language, OCaml offers great scalability for user projects by making it easy to build large systems without sacrificing maintainability. Thanks to the expressive type system, it is easy to refactor and adjust projects during development and as requirements change and evolve. The type-checker is reliable and covers 100% of the code, making it easier for developers to verify that data is used correctly in operations. With these features and the general benefits of FP, we're noticing a growing interest among software developers using OCaml to create web applications.

There are several tools and libraries designed for web development in OCaml and a lot is possible with the language. Some workflows are still being developed, and many developers are building new projects and sharing them with the open-source community for feedback.

Before we begin, there are three notable industry success stories, BeSport, Ahrefs, and Routine. BeSport is a popular French sports social app built using Ocsigen, a full-stack modular web framework for OCaml that empowers developers to build websites, web applications, and even mobile applications. Ahrefs, the world-leading marketing intelligence platform, uses full-stack OCaml for their web stack and has been very successful migrating to Melange. Routine, an integrated work platform that organises all your data in one place, uses Dream and wasm_of_ocaml to run their tools. With these companies showing how to leverage OCaml's potential, let's move on to the tools and libraries that make it all possible!

Ocsigen: A Complete Framework

Ocsigen is a collection of projects that provide a complete framework for developing web and mobile apps in OCaml. It is suitable for various uses, from simple server-side websites to client-side programs and complex client-server applications. The projects included under its umbrella are: Lwt, a general purpose concurrency library for OCaml; TyXML, for generating typed XML; Js_of_ocaml, which compiles OCamly bytecode from JavasScript and WASM; Eliom, which is a multi-tier framework for client-server web and mobile apps; Ocsigen server, a web server; Ocsigen Toolkit, a client-server widget library for Eliom and Js_of_ocaml; and Ocsigen Start, a higher level library providing user management and an application template that can be used as a basis for apps or to learn. The projects are mostly independent of each other, so users can pick and mix what they are interested in.

Ocsigen's design focuses on a couple of main strengths. Firstly, it takes full advantage of OCaml's expressive type system to check multiple programs' properties at compile time. This approach drastically reduces the development time of complex apps and makes it easier to refactor an application's code to facilitate new features. Secondly, using the Eliom framework enables multi-tier (also known as universal) programming where an application's client and server side are written using the same language and as a single code, with annotations in the code to indicate which 'side' the code should be run. As a result, both the server and client parts of a web application can be implemented as one program.

This method affords the developer a lot of flexibility to, for example, generate parts of pages either in the client or server code, depending on their needs. It also streamlines communication between server and client since programmers can use server-side variables in client code or call server-side OCaml functions from client code. It also makes it easy to deploy web and mobile multi-platform applications. Android and iOS apps are generated from the same exact code of the web app and run in a web view.

There are loads of resources available online to learn more about Ocsigen. Check out this presentation on Watch OCaml for an overview of the framework. For an example of what a mobile app developed using Ocsigen looks like, you can download the BeSport app on Google Play or the Apple app store.

Backends

Backend web development creates the foundations of the web, being the server-side portion of the website you don't see that implements the functionality of what you do see in your web browser. Common languages include Python, Ruby, and Java, just to name a few. OCaml has several web frameworks that enable you to do backend development, including options for beginners (e.g. Dream) as well as more experienced software engineers (e.g. Ocsigen).

Dream

Dream is a backend for OCaml that is well-liked for its simplicity and minimalist approach. Developer experience is a central tenet of its design, achieved by having a simple API and relying on fundamental OCaml types like string and list, only introducing a few of its own types. For a newcomer, the web framework offers extensive documentation and plenty of examples to get them started. Further examples of its quality-of-life features include unified error handling, a simple logger, a minimalist programming model that lets the developer create web servers just using functions, and cryptography helpers and key rotations to set up security options.

The Dream web framework is composed of several sub-libraries with different dependencies, which allow the user to port their projects to a variety of environments according to their needs. Furthermore, Dream is unopinionated and low-level, letting users pick and choose how they want to use it. They can swap out libraries to use other tools instead of its built-in templates (such as mlx). Essentially, the framework aims to be easy to use but highly configurable, giving the user the choice between customisation and simplicity. More concretely, Dream provides HTML templates (for OCaml or Reason); helpers for secure cookies and CSRF-safe forms; easy HTTPS, HTTP/2 and WebSockets support (meaning it supports most modern Web transport protocols); full-stack ML with clients compiled to Melange, ReScript, or Js_of_ocaml – and more!

If you want to try Dream, check out the tutorials. We also recommend this blog post on the Ceramic Hacker website, part two in an OCaml web development series that covers using Dream as a backend. It has some concrete code examples and gives a nice overview of a project. Of course Dream's homepage is also an incredibly useful resource.

Interop With JS, TS, and Wasm

JavaScript is the reigning monarch of programming languages for the web, powering web servers and adding interactivity and dynamic elements to web pages. With a vast array of tools and features in a mature ecosystem, JavaScript cross-compatibility is a must for languages aiming to expand onto the web. Wasm, or WebAssembly, on the other hand, is a portable compilation target that enables deployment on a variety of platforms. It is popular for its security guarantees, speed, and language- and platform- neutrality.

Js_of_ocaml

Js_of_ocaml compiles OCaml bytecode into JavaScript. This allows you to create dynamic and interactive elements on web pages and use tools like Node.js. You can install js_of_ocaml using opam or Dune, with the latter providing native support.

Some of the benefits of js_of_ocaml include its ease of use; it is simple to install and works with an existing installation of OCaml without requiring you to recompile your libraries. It also comes with existing bindings for many browser APIs and is stable and easy to maintain. Plus, performance comparisons have indicated that js_of_ocaml typically outperforms the OCaml type code interpreter. Furthermore, by generating JavaScript from OCaml bytecode, js_of_ocaml relies on a very stable interface that allows it to easily remain compatible with new compiler releases and most of the OCaml ecosystem.

To try it out yourself, there's a great js_of_ocaml tutorial by Jack Strand showing you how to create an interactive animation for a website. There are also some examples of js_of_ocaml in action, like this animated 3D view of the earth and a Boulder Dash style game.

Wasm_of_ocaml

Wasm_of_ocaml takes OCaml bytecode and transforms it into Wasm code. Originally forked from the js_of_ocaml compiler (and now merged back) it is of a similar, lightweight design. WebAssembly provides a sandboxed environment and enforces memory safety, making it popular among users who develop mission- and security-critical applications. Wasm_of_ocaml uses the WebAssembly garbage collection extension, removing the need to implement a garbage collector through other means and enabling good interoperability with JavaScript.

One of the compiler's biggest benefits is its speed, with some very impressive results from recent benchmarks driving renewed excitement. Compared to js_of_ocaml, programs compiled with wasm_of_ocaml are consistently faster. For example, Jane Street reported that they observed 2x-8x performance improvements using wasm_of_ocaml compared to js_of_ocaml. You can learn more about wasm_of_ocaml from our blog and in the repo's readme.

Melange

Melange is another backend for OCaml, consisting of a set of tools that makes it capable of generating and interacting with JavaScript. The tools include a compiler and compiler libraries, which can generate JavaScript code, and the runtime, which consists of a series of supporting libraries written in JS which output 100% JS. This makes interoperability and incremental adoption much easier for new users, albeit at the small cost of needing to write OCaml or Reason in a slightly different way.

One of Melange's biggest strengths is that it provides support for many different tools such as the editors VSCode, Vim, and Emacs, full integration with the very popular build system Dune, and interoperability with the documentation tool odoc which can generate a diverse range of documentation from the user's files. Overall, Melange's integration with the OCaml Platform gives the user access to the great resources of the OCaml Ecosystem.

Melange integrates with JavaScript through an expressive bindings language. This opens up the JavaScript ecosystem to the OCaml programmer, allowing them to use existing JavaScript packages and their own JavaScript libraries in OCaml projects and build applications that rely on features from the JavaScript ecosystem by working well with the syntax extension format ppx, Melange benefits from its performance, functionalities, and compatibilities.

You can try Melange in the Melange Playground and learn more about its finer details on Melange's documentation website.

For those familiar with ReactJS, there is an excellent online resource specifically aimed at React developers who want to learn Melange. It provides a hands-on introduction to Melange with several projects and examples. Melange offers excellent support for React codebases, with clear JS outputs and first-class support for many React patterns. David Sancho, one of Melange's maintainers, regularly produces very good content on his blog about the use of Melange in real-life applications, for example: Server-side rendering React in OCaml. This elegant interoperability with ReactJS demonstrates Melange's desire to interface easily with the JavaScript ecosystem, making OCaml a serious replacement for TypeScript, while continuing to benefit from the vast ecosystem of the JavaScript world!

Frontend

Frontend web development refers to the creation and editing of the graphical user interface of a website, including everything pertaining from HTML editing and rendering to web design, up to client-side web applications that run entirely in the browser. The underlying languages for frontend web development include HTML, cascading style sheets or CSS, JavaScript and WebAssembly. There are also popular platforms for frontend web development, such as Wordpress.

OCaml-VDom

The ocaml-vdom library, developed by Lexifi, implements an Elm-like architecture and VDOM for OCaml. An Elm architecture refers to a development pattern that is used to create interactive programs. The Elm architecture is a reformulation of a Moore machine, adapted to the construction of user interfaces. It enables the state of an application to be controlled using 3 ingredients:

  • A Model: the state of the application,
  • A View: A function which takes a model and returns the representation of the UI (in the case of Elm and OCaml-vdom, an HTML document); this document allows messages to be propagated, triggering the final ingredient,
  • An Update: A function that takes a Message (propagated by the View) and the current model as arguments and computes a new model, which will be passed to the view to rebuild the UI.

In practice, the Elm architecture also introduces the notion of Command and Subscription to interact with discrete effects and communicate with the outside world. This approach is very expressive for describing reactive interfaces and is the result of several iterations described by the creator of Elm in the following essay: Elm: Concurrent FRP for Functional GUIs. After much experimentation, he has drastically simplified the user experience of Functional Reactive Programming with the Elm architecture!

OCaml-vdom is a very faithful implementation of the Elm architecture, giving OCaml the ease and expressiveness to describe rich web interfaces. To explore some examples and test OCaml-VDom yourself, visit the ocaml-vdom library and get hacking!

Bonsai

Bonsai is a client-side web framework created by Jane Street that lets users build web pages from the client (the browser) by creating components. For those familiar with other web development frameworks, Bonsai fills the same role as, for example, Angular and Vue, but it is written entirely in OCaml.

The structure of Bonsai is as a group of components, each representing one part of the final page, available in the bonsai_web_components repo. One of the benefits of the framework's design is that, instead of structuring its components like a tree, it does so in a "structured acyclic graph". This lets programmers create components that can 'communicate' with each other much more easily than with frameworks that use the tree structure.

To learn more about the framework, we definitely recommend the same article series mentioned above from the 'Ceramic Hacker' blog, especially starting from the Setting up Bonsai post. In it, Alexander Skvortsov illustrates why he found Bonsai excellent for building "safe, massively scalable, performant UIs".

… And Many More

There are plenty more libraries available for web development in OCaml, and we have not been able to include them all in this post. For example, Brr provides a toolkit for programming browsers in OCaml using Js_of_ocaml; the Lwd library enables reactive programming in the browser through a simple form of incremental computation; Vif is an experimental program that runs an OCaml script and launches a web server from it; React is a functional reactive programming library for OCaml; ReScript is a typed language that grew out of OCaml, now used to write fast and human-readable JavaScript for the web; and Wasocaml is another WebAssembly compiler developed by OCamlPro which works differently than Wasm_of_ocaml.

Furthermore, several big OCaml projects were developed in connection with extensive research done at universities, including projects like Ocsigen and MirageOS (check out Unipi for a great example of a static web server built with MirageOS). For example, 'Rethinking Traditional Web Interaction' is an interesting paper exploring the future of web development far ahead of its time, research which directly impacted Ocsigen's design!

While this post has focussed on application development frameworks, MirageOS offers a robust, mature, and efficient deployment solution similarly grown out of a rich academic history. When deploying a traditional application, it is common to separate it into multiple execution units (i.e., microservices). However, each of these services requires an OS (and ideally containerisation). MirageOS is a framework that allows developers to define an operating system (executed by the CPU's hypervisor) that only runs a limited set of tasks: a unikernel. This enables the creation of very lightweight operating systems designed to perform only a restricted set of tasks, significantly reducing the attack surface and boot time. As a result, MirageOS provides an advanced set of tools for development using microservices.

Since OCaml is an excellent choice for building compilers and build systems, there are many advanced static web site generators to choose from! Without going into too much detail, we'd like to mention Soupault, a highly flexible HTML processor that offers a great deal of freedom when it comes to building static pages; Stog, a mature tool with a huge number of plugins; and YOCaml, a very generic framework for composing your own static site generator. There are many others, and since a static site generator is a specialised version of a build system, Dune can even be used as one! In any case, OCaml is a useful (and fun) choice for creating a static site, which also works well alongside MirageOS for deploying very small static servers or using Git as a static file system (directly conceivable with Yocaml_git).

These are just a few examples of the things we didn't cover here, and there are many more great projects out there to discover. If you think we've missed one, please let us know!

Until Next Time

Thank you for checking out this article on web development in OCaml. We have tried to capture as much information as possible in one place (as you can probably guess from the length of this post!) and we look forward to hearing your feedback. Have you developed any web applications using OCaml? What was your experience? Connect with us on Bluesky, Mastodon, Threads, and LinkedIn. We look forward to hearing from you!

Open-Source Development

Tarides champions open-source development. We create and maintain key features of the OCaml language in collaboration with the OCaml community. To learn more about how you can support our open-source work, discover our page on GitHub.

Explore Commercial Opportunities

We are always happy to discuss commercial opportunities around OCaml. We provide core services, including training, tailor-made tools, and secure solutions. Tarides can help your teams realise their vision