Automatically reload your Val Town project in the browser when any of its files change. No more manual refreshing to see your updates!
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.
reload.val.run
proxy, which will show you the error, and poll for non-error responses, and reload the page when it gets one.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);
This project is a port of reloadOnSave.