: nply/liveside

liveside

A tiny live-reload server written in POSIX-first portable C99. It watches a directory tree for changes and pushes the browser a Server-Sent Events (SSE) reload message, which reloads the page.

Runs on macOS, Linux, the BSDs, and Windows. The main server code stays POSIX-first (poll, dirent, unistd, BSD sockets, stat) and uses TinyCThread for portable threads/mutexes. On Win32 toolchains that do not provide POSIX headers directly, use packages from win32ports. Project-owned code under ports/ is reserved for reusable pieces that are core to liveside and may be extracted later, such as socket smoothing, ignore-file matching, and the native Windows watcher.

It is deliberately not a static file server — it only ever answers two requests, /livereload (the SSE stream) and /liveside.js (the client snippet). Your actual site keeps being served by whatever you already use — darkhttpd, lighttpd, python3 -m http.server, anything — on its own port. liveside just sits alongside it (hence the name).

It fills the same role as the autorefresh target in the saikrupagas.com Makefile (ls | entr make refresh, which rebuilds and then simulates a keypress in Arc/Firefox), but works in any browser without AppleScript/xdotool or driving a specific app.

Build

Fetch dependencies with mor, then build:

make deps
make

make also runs make deps automatically. Dependencies are recorded in requirements.ini and downloaded into thirdparty/, which is ignored by git. TinyCThread is fetched this way and compiled alongside liveside.c.

On Windows, make deps fetches TinyCThread plus win32ports headers for POSIX interfaces such as dirent.h, getopt.h, sys/time.h, and unistd.h. The Makefile detects $(OS)=Windows_NT, links Winsock, includes the native ReadDirectoryChangesW watcher port, and produces liveside.exe.

Style

liveside adopts the suckless coding style for C code. Use make format / make check-format with .astylerc; see STYLE.md.

The served /liveside.js body is generated from client/liveside.js into client/liveside.js.inc at build time and included by the C preprocessor, so edit the JavaScript file directly rather than maintaining a C string copy.

Run

./liveside -d /path/to/site -p 8081

Options:

Ctrl-C stops it.

License

BSD 3-Clause. See LICENSE.

Client

liveside serves its own client script, so pairing it with an existing static server (e.g. darkhttpd on 8000 for the site, this on 8081 for reload) needs nothing copied between them — just point an absolute <script> tag at liveside's port:

<script src="http://localhost:8081/liveside.js"></script>

That's a cross-origin request, which script tags don't need CORS for. It auto-detects the right origin to connect back to from its own src. If you instead copy client/liveside.js into the site itself and load it same-origin, set window.__RELOAD_PORT__ before the script tag so it knows where to find the SSE stream.

How change detection works

Ignore rules are loaded from .gitignore and .livesideignore files at the watch root and in nested directories. Parent rules apply before child rules; within one directory, .gitignore is read before .livesideignore so liveside-specific rules can override with !. Ignored paths are excluded from polling snapshots and watcher scans, and native watcher events for ignored paths are filtered before reloads are broadcast.