Introduction

Motivation

Most websites consist of at least two tightly coupled components. One runs in the browser, and the other runs on a web server.

  • Client
    • Runs in the browser
    • Responsible for user interaction
    • Typically written in JavaScript
    • Untrusted execution environment
    • Unreliable persistent local state
  • Server
    • Runs in a datacenter
    • Responsible for business logic
    • May be written in a wide variety of languages
    • Trusted execution environment
    • Reliable persistent global state

Coders work hard to try to make the website appear like a single piece of software to the website visitor, but this requires a lot of hidden complexity.

Kweb lets you write your entire app as a single piece of software. It does this by moving as much of the logic to the server as possible, leaving a simple but powerful interface to the web browser. This allows you to build beautiful responsive website much more quickly.

It’s written in Kotlin, a modern powerful programming language that is rapidly growing in popularity. For example, Kotlin is now being promoted by Google as a replacement for Java in Android development.

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 a small HTML file including optimized instructions for building the page, and a client which connects back to the web server via a WebSocket. The client then waits and listens for instructions from the server.

To minimize latency, Kweb can preload instructions to the browser to modify the DOM instantly in response to browser events, perhaps to disable a button or temporarily display a “spinner”. This solves one of the most serious problems affecting some of Kweb’s philosophical ancestors, Wicket and Vaadin (which shared Kweb’s “server driven” approach).

Kweb is designed to be efficient. All operations are handled asynchronously, thread and memory usage are minimized. Kweb runs on the JVM, which is 5-10 times faster than Node.js.

Kweb also takes an end-to-end approach to state. You can bind the value of a DOM element to a field in your database, and have it update in realtime automatically.

Features

  • Free as in speech, licenced under LGPL v3.0
  • A unified codebase for your webapp, from database to DOM
  • End-to-end Kotlin (Why Kotlin?)
  • Bind DOM values directly to a value in your database and have them update in realtime
  • Statically typed HTML DSL - let your IDE catch bugs so you don’t have to
  • Efficient server-side rendering, DOM caching, and instruction preloading
  • Connect to almost any back-end key/value store and pub/sub service for unlimited scalability