Most web pages show what was true when they loaded. If an order ships or a new comment arrives, you don't see it until you refresh. Live updates fix that: the server sends the change to the page as it happens.
Starting with 0.6, NTNT has this built into the runtime. There's nothing to install and no separate server to run.
Two ways to push updates
Server-Sent Events (SSE) send updates one way, from the server to the browser. They suit most live pages: dashboards, notifications, progress bars, a feed that updates itself. Every modern browser supports them through EventSource.
WebSockets carry messages in both directions. Use them when the browser also sends a steady stream of messages back, as in a chat or a shared editor.
What it looks like
This server sends the time to every open page once a second:
import { broadcast, publish, schedule } from "std/concurrent"
import { sse } from "std/http/server"
let ticks = broadcast("ticks")
get("/events", fn(req) { return sse(ticks) })
schedule(1000, fn() {
unwrap(publish(ticks, map { "at": str(now()) }, map { "event": "tick" }))
})
listen(8080)
The page listens with two lines of JavaScript:
const events = new EventSource("/events")
events.addEventListener("tick", (e) => console.log(JSON.parse(e.data).at))
broadcast creates a named channel, and publish sends a message to everyone listening on it. /events is an ordinary route, so your middleware and login checks run before the stream opens, just as they do for any other page. A WebSocket endpoint can listen to the same channel.
What to keep in mind
Updates are kept in memory by one running copy of your app. A browser that disconnects misses whatever was sent while it was away, so the page should reload its data when it reconnects. If you run several copies of the app behind a load balancer, each copy only reaches the browsers connected to it.
To try it, save the example as server.tnt, run ntnt run server.tnt, and point a page at /events. The live updates recipe has the complete example, and the agent guide covers WebSockets.