Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Wd-40, a static webserver with automatic hot-reloads (github.com/baalimago)
108 points by baalimago on Aug 20, 2024 | hide | past | favorite | 84 comments
It works by injecting a websocket script which listens for file changes. The filechanges are detected using the go fsnotify package, which in turn uses the different OS's equivalent to inotify.

I basically got bored with alt-tabbing and refresing when developing 'vanilla-js'. The hot-reload in the modern frameworks are very nice, so figured I'd recreate it.



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.


I also hate WD-40 as a product because it's marginally useless as a lubricant or as a penetrating oil when there are far better products for each use.


It's excellent for Water Displacement, which is what its purpose actually is.

Such as if you have ignition wires soaked with water and shorted, it will get you going again.


Me wonders - remembering the recent here post about the flooded underground silo with electronics - could it be flooded with WD-40 instead of water?


The common recommendation is to flood wet electronics first with distilled water and then with isopropyl alcohol


That comment has been living in my head rent free all week. The author of that post was good with imagery.


It's a brand name now, they also sell grease.


I sprayed it near my squeaky bike brake hinge thinking it would remove the squeak. I now know I was an idiot and completely ruined the bike's brakes.


Brake cleaner for diskbrakes unless it's a sound of metal on metal and you have to replace the brake pads. And for rim brakes if there's a metal sound a stone is stuck in the rubber part of the brakes, either get it out or replace as well if it's already worn down a fair bit.


Just be happy you learned that lesson on a bike and not on a car


They (WD-40 brand) do sell a penetrating oil: https://www.wd40.com/products/penetrating-oil/


I'd say because it's not a lubricant it's penetrating oil, anti rust, anti moisture (its original purpose).

And even when used as that most people I'd guess don't shake the can, a long shake, as required.


I have much better luck with PB Blaster. I can't count how many rusty old nuts and bolts I sprayed with WD-40 only to have to follow it up with PB Blaster to get the job done.


PB Blaster is the product everyone thinks WD-40 is. Even still, I wouldn’t use it in the place of real oil/grease/lubricant but in a pinch it’s far better than WD-40 for those odd chores.


For sure. PB Blaster is my go-to when I find a bolt on my truck that hasn't been touched since it left the factory in '88. Its a quick fix for a stuck bolt, but still not a great solution for a squeaky door hinge.


Using the same name also will make searching anything related to this much more difficult (as will using 2 letter 2 number name)


> not make any difference to them.

It does to the US government... trademarks are industry-specific. It is absolutely legal for people to use the exact same trademark for different classes of business.

Of course they could still probably sue you into oblivion anyways, even if they're wrong.


Hmm.. That's a good point, thank you. I'll change the name


Good job with the renaming - WD-42 could have been also a good choice.


Really should rename it tap-and-die.


do you know what a hammer is? I tell you hwat


Trademarks have scopes.


It’s wd-41 now lol


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


>I thought the name was inspired by a cheap, easily available lubricant that comes in handy for every home.

It is, especially it's rust-repellent properties. The only 'plug-and-play' static webserver I found was, well... https://github.com/static-web-server/static-web-server/ which is written in Rust (I didn't look around super hard). But, being a gopher, and since it lacked live reload, I wrote my own.


wd-40 is not a lubricant. Stop using it as one. You're just making the problem worse. Use lubricating oils.


Put some wd-40 on your bike's brakes and see if you think it's not a lubricant.

Maybe you think it's not a _good_ lubricant? But a lot of its use is to extract stuck things which requires a thin lubricant


> Maybe you think it's not a _good_ lubricant? But a lot of its use is to extract stuck things which requires a thin lubricant

The word you are looking for is “penetrating oil”. The problem with a too broad definition of “lubricant” is that I wouldn’t use Coca Cola to lube my engine or KY Jelly to lube my bike chain. WD-40 is a shitty lubricant for metal-on-metal moving parts, so it’s helpful in that context to say that it isn’t a lubricant.


Over 1/3 of WD-40 is made of a lubricant. My salad dressing is over 1/3 oil. Does that make it lubricant, or is it actually still salad dressing?


Not sure who's arguing what and on what side here but when making a sandwich, adding dressing or oil to the sandwich is often referred to as "adding a lubricant" to the sandwich.


Third option: It's possible for salad dressings to be lubricants.


It may temporarily act like a lubricant, but we typically expect lubricants to last longer than a month or so, and WD-40 does not. It's meant as a solvent, and can be followed up with an actual lubricant.


> we typically expect lubricants to last longer than a month or so, and WD-40 does not

Neither does KY and yet here we are.

While WD40 wasn't designed as a lubricant it does function as one.

People using heavy equipment often grease their machines daily but no one claims grease isn't a lubricant.

I have to put bar oil in my chain saw every time I use it, and often have to refill it during the day. Is that not a lubricant?


But you are aware and know that you have to reapply KY every time you want to deal with some ... em... tight situations. And after you're done, you intentionally wash it off, because you don't want those places to be lubricated during non-active times.

But a bike chain is a thing that you want lubricated for a long time, and not have to think about lube every time you want to use it (well.. in a normal, bike-driving way). Is it still lubed? Did it rain the last time you drove a bike? When was the last time you lubed it? Some other lubricant would last much longer and lubricate much better, and with a bike chain, lasting many months is good thing.

That's why we have and use different kind of lubricants for different things, and WD40 is not a "good choice" for most of the stuff some people use it for (like bike chains... or anal).


The point is, different lubricants have a different effective time.

As I said: a chainsaw is constantly adding lubricant to the bar. Meanwhile the swing I built for my son had white lithium sprayed on it and still doesn't make a sound, after full exposure to 3 monsoonal wet seasons.


People use WD-40 for anal?



What else are you going to use to penetrate the joint and loosen up seized nuts?

I'll see myself out.


What’s a good lubricant for metal on metal (aluminum in specific)?


Tri-flow. Also good as a penetrating oil, and smells like bananas.


It also has a lot of teflon.


wd-40 brand makes several lubricants now


It would be self defeating if written in Rust


Except "rust" in rust isn't about iron oxidation, but rather a fungi [0]

[0] https://www.reddit.com/r/rust/comments/27jvdt/internet_archa...


Doesn't seem that final in that extract.

> <graydon> > A little. Also big metallic things. And rusts and smuts, fungi. And it's a > <graydon> > nice substring of "robust".

> <graydon> IOW I don't have a really good explanation. it seemed like a good name. (also a substring of "trust", "frustrating", "rustic" and ... "thrust"?)

> <graydon> but then everyone thinks it's a pun on "chrome" so maybe we should stick with that

And given that now all the lore around it is about oxidation, I guess that's what stuck?

These old IRC dumps make me nostalgic instantaneously. There was a time not that long ago when we were still mostly fine with plain text for complex communications.


> … mostly fine with plain text for complex communications

Like on this very website? :)


I think you missed one of the more important lines:

> I think I named it after fungi. rusts are amazing creatures.

Sure, there’s room for doubt, but not that much room.


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.


I am the self-appointed HN sales pitch for https://github.com/sigoden/dufs, a fileserver including webdav.


Does dufs have the auto reload feature of this project?


No auto/live/hot reload, just a well-maintained single (rust) binary static fileserver with .zip, upload, auth, & webdav.


I am a big fan of WebDAV. DUFS is new to me, I will check it out.


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.


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.


>Does that mean it doesn't auto-refresh if dependencies

It does refresh on all other file changes. I first thought about trying to figure out what js/css was used on which page but that turned too complicated. So now it refreshes on all js/css files [1].

[1]: https://github.com/baalimago/wd-41/blob/main/internal/wsinje...


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.)


1. No, it doesn't react to file additions/deletions at the moment, but as there's support for this in fnotify which is handling file change notifications [1] I'll add this shortly. wd-41 is still quite early in development.

2. This was my initial idea as well: to simply inject the ws-load script tag on the fly. But it would require basically writing a static file server from scratch, which I didn't feel like doing (I have a blog to write, not static file servers!). Currently the solution is based on the go standard library fileserver handler [2] which makes the solution simple and effective. So i decided on the mirrored approach with the idea that the result for the end user should be the same, apart for the temporary directory where the mirrored files lives. I haven't yet detected any speed-issues in the mirroring process or the file-watch process, which I think is the only downside (please correct me if I'm wrong).

[1]: https://pkg.go.dev/github.com/fsnotify/fsnotify#hdr-Watching...

[2]: https://github.com/baalimago/wd-41/blob/main/cmd/serve/serve...


You can do this with inotify-tools and a wrapper script. Needs a little something on the browser side to make it seamless however.


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,


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


There’s also Content-type: multipart/x-mixed-replace, though last I checked it had the downsides of (a) only working in Firefox and (b) causing the loading spinner to run forever.


I assume WebSockets is probably the preferred way so all the other proposals fell on their face. This one seems to be using WS as well.


So what happens when you have more than 64K simultaneous viewers?


Sounds similar to the 'live server' plugin in vscode


Does it support SSI?


No. Didn't even know what SSI was until I googled around. Seems cool, but the as I host my personal website on s3 + cloudfront (the usecase of which I made wd-41), which doesn't support SSI, I don't think I'll add it.


I understand


I am glad such tool exists, but PHP was "hot-reloading" like what, 20 years ago?


Updating a PHP file didn't update the content in the browser without a page refresh.


What this does != what PHP does.


Static web servers have been a solved technical problem for going on 25 years.


Yeah, but this one actually refreshes the browser when a file is modified on disk (of the server). I don't recall seeing that in any other webserver, at least not out of the box.

It is pretty clever, not sure how much need I have for it, but it's an interesting idea.


Extremely large beverage holder...bubble dome...a horn that plays "La Cucaracha"...


> Extremely large beverage holder.

You joke, but the only thermo mug that I've been able to find that fits into my car is an off-brand one my mother-in-law picked up from a bargain bin in Lidl. None of my five mugs or bottles fit.


Is there a small and portable one you recommend?


Someone above recommended devd, and it looks pretty nice. https://github.com/cortesi/devd


I personally like busybox httpd, because sometimes it already is there.


mini_httpd, merecat, [a-z]httpd (choose one), OpenBSD httpd is nice but not portable. Your OS likely has a a built-in web server. Hell, Microsoft shipped something called Personal Web Server with Windows 95/98 nearly 30 years ago.

Stop inventing new static web servers. Contribute patches to an existing project if you feel so inclined but this has been a solved problem for decades by very intelligent people who understand how the Internet works. We've gone full circle from bloated behemoths like Netscape, to serving from kernel mode (http.sys, Tux Web Server, etc.) and back again.


These responses are telling me there is in fact room in the market.

Take pdf viewers for example. I hated all of them until I found Zarthura. I’m glad someone took the time to make that.


> Static web servers have been a solved technical problem for going on 25 years.

That only shows your ignorance. By that logic, transportation has been a solved problem for millennia. We were moving from A to B for quite some time.

When your wife tells you "Hey, look what I cooked for dinner"? Do you tell her "I have seen this dish 30 years ago, why don't you develop new recipes instead?"

Find something better to do than belittling others side projects that they shared for fun.


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?


Your link, links to this thread ..


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.


Not a lawyer, but I think it might be ok, if the products are totally unrelated, which they are. I doubt anyone at the management of the company behind WD-40 would even know what a http server is, or could name one.

Also, it is written Wd-40 not WD-40..

As long as it stays a dev http server, it should be fine.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: