How tomig06/tinyreload works
Purpose and Entry Point
tinyreload is a single Go binary that serves a static-site directory and live-reloads connected browsers when files change. The executable entry point and server orchestration are in tinyreload.go; module dependencies are defined in go.mod.
CLI and Process Startup
The process accepts -path for the static-root directory and -addr for the HTTP listen address. Startup configures the file server, WebSocket endpoint, embedded client asset, filesystem watcher, and HTTP listener.
• tinyreload.go
• go.mod
Static File Serving and HTML Transformation
Requests are resolved against the configured static root. Directory handling redirects or resolves paths toward index.html. HTML responses are modified to inject the browser client script, while HTML is served with no-cache behavior so reloads fetch current markup.
• tinyreload.go
Embedded Browser Runtime
The reload client is bundled into the Go binary rather than copied from the served site. Browsers receive it at /tinyreload.js; it establishes a WebSocket connection and applies reload commands.
• injectable/tinyreload.js
• tinyreload.go
Live-Reload Transport
The server maintains WebSocket-connected browser clients and broadcasts filesystem-change events as file URLs. The browser runtime distinguishes CSS updates from other changes: CSS is refreshed in place, while non-CSS changes trigger a full page reload.
• tinyreload.go
• injectable/tinyreload.js
Filesystem Watch Pipeline
A recursive watcher monitors the configured static root and its subdirectories. Change events are filtered to ignore dotfiles, then translated into browser-facing paths and sent through the WebSocket broadcast path. This is the main boundary between local filesystem events and browser reload behavior.
• tinyreload.go
Runtime and Delivery Model
The architecture is local-process oriented: Go hosts HTTP and WebSocket services, serves user-provided static files, and embeds its only client-side dependency. No database, cloud infrastructure, build pipeline, or external runtime service is required. setup.sh provides repository setup for local development.
• tinyreload.go
• injectable/tinyreload.js
• setup.sh
Components 14
Go server
Single local-process runtime.
- CLI flags · Accepts static root and listen address.
tinyreload.go - Server orchestration · Configures HTTP, WebSocket, assets, and watching.
tinyreload.go - Static file handler · Resolves directories and serves transformed HTML.
tinyreload.go - HTML injection · Injects the embedded reload client and disables HTML caching.
tinyreload.go - Embedded client asset · Served at /tinyreload.js from the binary.
injectable/tinyreload.js - WebSocket client hub · Tracks browsers and broadcasts changed file URLs.
tinyreload.go - Recursive filesystem watcher · Monitors the static root and subdirectories.
tinyreload.go - Change filter and mapper · Ignores dotfiles and maps changes to browser paths.
tinyreload.go - HTTP listener · Hosts static, client asset, and WebSocket endpoints.
tinyreload.go - Go module dependencies
go.mod
Browser
- Site page
- Reload runtime · Refreshes CSS in place or reloads the page.
injectable/tinyreload.js
Other components
- Static root · User-provided site files monitored and served locally.
- Local setup script
setup.sh
Connections 18
- CLI flags → Server orchestration: configures
- Go module dependencies → Server orchestration: provides dependencies
- Server orchestration → Static file handler: configures
- Server orchestration → WebSocket client hub: configures
- Server orchestration → Recursive filesystem watcher: starts
- Server orchestration → HTTP listener: starts
- Static root → Static file handler: serves from
- Static file handler → HTML injection: transforms HTML
- HTML injection → Site page: returns injected page
- Embedded client asset → HTTP listener: served at /tinyreload.js
- HTTP listener → Site page: serves HTTP
- Site page → Reload runtime: loads
- Reload runtime → WebSocket client hub: connects WebSocket
- Static root → Recursive filesystem watcher: monitors
- Recursive filesystem watcher → Change filter and mapper: emits file events
- Change filter and mapper → WebSocket client hub: broadcasts changed URL
- WebSocket client hub → Reload runtime: sends reload command
- Local setup script → Go module dependencies: prepares local development