Kweb’s goal is to eliminate this server/browser separation so that your webapp’s architecture is determined by the problem you’re solving, rather than the limitations of today’s tools.

Modern websites consist of at least two tightly coupled components, one runs in the browser, the other on the server. These are often written in different programming languages and must communicate with each other over an HTTP connection.

How does it work?¶

Kweb is a self-contained Kotlin library that can be added easily to new or existing projects. When Kweb receives a HTTP request it responds with the initial HTML page, and some JavaScript that connects back to the web server via a WebSocket. The page then waits and listens for instructions from the server, while notifying the server of relevant browser events.

A common concern about this approach is that the user interface might feel sluggish if it is server driven. Kweb solves this problem by preloading instructions to the browser to be executed immediately on browser events without a server round-trip.

Kweb is built on the excellent Ktor framework, which handles HTTP, HTTPS, and WebSocket transport. You don’t need to know Ktor to use Kweb, but if you’ve already got a Ktor app you can embed Kweb as a Feature.