A cache-busting http server script in ruby
"All of this can be yours/just give me what I want/and no one gets hurt"
– Bono, Vertigo
If you’ve done much Javascript development, or simple web development without a webserver backend, you don’t want to set up a complex framework. Just give me the pages: I want to be able to start a simple webserver to give me the current directory structure as a website. You can’t simply load the pages into a browser using file://
because that screws up the relative paths that our sites rely on. What’s the best way of doing this?
Python’s SimpleHTTPServer
One simple way is:
This does a great job, but there’s one small problem: caching. Ordinarily during development you’ll want the browser to request the HTML each time, and the python server doesn’t do that out of the box.
Ruby’s WEBrick with adding cache-busting
Here’s a small script I borrowed from pmarti and tweaked. It lives in the bin/http
file on my path: I just type http
in the relevant folder and I’m set.
Hope it’s helpful. Do you know of a better way of doing it? Feel free to share…
Share on BlueSky to comment.