August 18th, 2024

Show HN: Wd-40, a static webserver with automatic hot-reloads

wd-41 is a static web server for web development with hot-reloading, 73.64% test coverage, and easy installation. It automatically refreshes the browser when file changes occur, enhancing development efficiency.

Read original articleLink Icon
CuriositySkepticismAmusement
Show HN: Wd-40, a static webserver with automatic hot-reloads

wd-41 is a static web server designed for web development that features hot-reloading capabilities, automatically refreshing the web browser when changes are made to the served files. The project boasts a test coverage of 73.64%. To use the server, one can start it with the command `wd-41 s|serve <relative directory>`, which defaults to serving the current directory if no specific directory is provided. Installation can be done via Go with the command `go install github.com/baalimago/wd-41@latest`, or by running a setup script using curl. The architecture of wd-41 involves copying website content to a temporary directory, injecting a `delta-streamer.js` script into HTML files, and hosting the mirrored content. A WebSocket connection is established to monitor the original file system for changes, allowing new files to be mirrored and notifying the browser to reload the page if the current window matches the updated file. This setup enhances the development experience by eliminating the need for manual page refreshes.

- wd-41 is a static web server with hot-reloading features.

- It has a test coverage of 73.64%.

- The server can be started with a simple command and installed via Go or a setup script.

- The architecture includes a temporary directory for mirrored content and WebSocket connections for real-time updates.

- It streamlines the development process by automatically refreshing the browser on file changes.

AI: What people are saying
The comments on the article about wd-41 reveal various perspectives on the tool and its implications.
  • Several users compare wd-41 to existing tools like LiveReload and BrowserSync, discussing their preferences and experiences.
  • Concerns are raised about the name "wd-41" potentially leading to legal issues with the WD-40 company.
  • Questions about the technical implementation of wd-41 arise, including its mirroring capabilities and support for server-side includes (SSI).
  • Some commenters note that static web servers have been a well-established solution for many years.
  • There is a mix of appreciation for the tool's existence and skepticism about its novelty in the context of existing technologies.
Link Icon 17 comments
By @pwg - 9 months
My only comment is: "be prepared for a cease and desist from the lawyer's for the real WD-40 company" over the name choice.

The fact that they make spray lubricants and you have a website re-loader will likely not make any difference to them.

By @Brajeshwar - 9 months
I thought the name was inspired by a cheap, easily available lubricant that comes in handy for every home.

I've tried many simple servers for experimenting with simple static websites (HTML, CSS, JS). I'm currently settled on LiveReload[1] and BrowserSync[2]. LiveReload attaches to other tooling and is more straightforward, while Brower-Sync when looking across a few multiple browsers (out of habit). I'm not particularly fond of tooling that attaches to an IDE, but I like more of the ones that I can pipe with arguments. But then again, I do straightforward stuff these days.

LiveReload should also be easily attachable to a simple `python -m SimpleHTTPServer 8000`.

1. https://github.com/livereload

2. https://browsersync.io

By @onetom - 9 months
I've settled on devd (modd) for the past few years. https://github.com/cortesi/devd

It's a single file go executable. Supports CORS too. I use it via direnv & nix-shell.

By @password4321 - 9 months
I am the self-appointed HN sales pitch for https://github.com/sigoden/dufs, a fileserver including webdav.
By @meblum - 9 months
Here’s my hot-reload tool https://github.com/meblum/serv it reloads html files when any of its dependencies have changed. Written in Go with zero dependencies and requires no config. Uses server-sent-events to notify webpage of updates. Feedback appreciated.
By @pierrec - 9 months
Nice, I've used an editor plugin for this before, but I like that this isn't tied to any specific editor. Actually Hugo also does this, though again that's tied to a framework:

https://gohugo.io/getting-started/usage/#livereload

Also curious about this: "The delta-streamer.js script then checks if the current window origin is the updated file. If so, it reloads the page."

Does that mean it doesn't auto-refresh if dependencies (scripts, stylesheets, etc) are updated? Maybe there's room for improvement here though I'm not sure how I would approach it. Maybe just an option to skip the check would do the job.

By @winter_blue - 9 months
This is pretty cool. I have two questions, regarding the mirroring:

1. For the mirroring, are you using something like rsync (with modifications for the web socket script injection) underneath? Also, will the mirroring reflect destructive changes (like rsync's --delete flag), like if a directory or file is deleted in the original content directory?

2. Could you avoid mirroring the content directory, and just directly serve the original content directory, by just simply on-the-fly injecting the relevant script tag in text/html files? (Or, only mirroring those text/html files, and serving the remaining files from the original content directory.)

By @mixmastamyk - 9 months
You can do this with inotify-tools and a wrapper script. Needs a little something on the browser side to make it seamless however.
By @nashashmi - 9 months
Should W3C work on a way to do socket connections without JS? It is not high on the list but is popular enough. Things that are more important to be done without JS are horizontal scrolling of items (marquee on steroids?) and slideshows,
By @1oooqooq - 9 months
between this and liveview... and the infinity websites doing timed or pull-check reloads...

is this the best the web have to offer in terms of standards to keep one tab with fresh content? i recall some push standard discussions

By @bufferoverflow - 9 months
So what happens when you have more than 64K simultaneous viewers?
By @dufzh - 9 months
Sounds similar to the 'live server' plugin in vscode
By @Alifatisk - 9 months
Does it support SSI?
By @est - 9 months
I am glad such tool exists, but PHP was "hot-reloading" like what, 20 years ago?
By @wannacboatmovie - 9 months
Static web servers have been a solved technical problem for going on 25 years.
By @drpossum - 9 months
Here's literally the same link to a repo from the author from two days ago

https://news.ycombinator.com/item?id=41284189

How many times do you feel the need to repeatedly hype this?

By @AbraKdabra - 9 months
I really don't know how you didn't think of the "dodging potential lawsuit" before posting it here, I mean, you didn't know that using actual product names is wrong? It's a shame though, I liked the word play.