• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
stevekrouse

stevekrouse

live-reload

Middleware for live-reloading HTTP vals when they change
Public
Like
5
live-reload
Home
Code
6
README.md
client.ts
H
demo.tsx
H
error-proxy.ts
main.ts
utils.ts
Branches
1
Pull requests
Remixes
3
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
Code
/
Search
https://stevekrouse--27760cd0170411f0a475569c3dd06744.web.val.run
README.md

Live-Reload for Val Town

Automatically reload your Val Town project in the browser when any of its files change. No more manual refreshing to see your updates!

πŸ“Ί Demo video

Features

  • πŸ”„ Instant page reloads when your code changes
  • πŸ”Œ Simple one-line integration
  • 🧠 Smart polling frequency based on edit recency
  • πŸ›‘οΈ Error state handling with automatic recovery
  • πŸ” Works only in development environments (*.val.run domains)

Installation

Import and use the liveReload wrapper function in your main entry point:

import { liveReload } from "https://esm.town/v/stevekrouse/live-reload/main.ts"; const handler = (req: Request) => { /* your fetch handler */} export default liveReload(handler, import.meta.url);

You can also remix this example to get started.

How It Works

  1. Detection: The system uses the Val Town API to monitor your project for changes
  2. Long Polling: The client periodically checks if the project has been updated
  3. Smart Polling: Polling frequency adjusts based on how recently the project was edited:
    • < 15 minutes: Polls every 500ms
    • < 3 hours: Polls every 1 second
    • > 3 hours: Polls every 5 seconds
  4. Reload: When a change is detected, the page is redirected through a special proxy that handles error states
  5. Error Recovery: If val returns an error, we'll redirect you to our reload.val.run proxy, which will show you the error, and poll for non-error responses, and reload the page when it gets one.

Example Usage

Here's a complete example using Hono:

/** @jsxImportSource npm:hono/jsx **/ import { Hono } from "npm:hono"; import { liveReload } from "https://esm.town/v/stevekrouse/live-reload/main.ts"; const app = new Hono(); app.get("/", (c) => { return c.html( <body> <h1>My App with Live Reloading</h1> <p>Edit this file and save to see instant updates!</p> </body>, ); }); // Enable live reloading export default liveReload(app.fetch, import.meta.url);

Troubleshooting

Live reload isn't working

  1. Check the domain: Live reload only works on *.val.run domains (not custom domains)
  2. Check the console: Look for messages about live-reload being skipped
  3. Iframe detection: Live reload is disabled in iframes (like the Val Town editor preview)

Disabled on development

  • Only works on *.val.run domains (not custom domains)
  • Disabled in iframes (including the Val Town editor preview)
  • Requires the Val Town API to be accessible

Prior Art

This project is a port of reloadOnSave.

HTTP
  • demo.tsx
    stevekrouse--27…44.web.val.run
  • error-proxy.ts
    stevekrouse--f403b6c2170811f0b477569c3dd06744.web.val.run
Code
README.mdclient.ts
H
demo.tsx
H
error-proxy.ts
main.tsutils.ts
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
Β© 2025 Val Town, Inc.