3

I'm looking for an HTTP server that can be invoked from the command line for localhost. I want it to be able to watch static html and css files for changes and reload the page viewed in a browser when changes are noticed.

I've found a number of nodejs packages filling this task, but many of them don't work well. Here are the nodejs packages I tried:

  • live-server is doing it good for the default default.html and index.html pages. If I want to watch an HTML page which is not index.html or default.html, I don't see the browser actually updates.
  • fast-live-reload perhaps is not suited for static web pages and only for web applications of some sort.
  • livereload just doesn't work at all, perhaps it is not suited for static web pages and only for web applications as well

EDIT

  • nginx is an overkill.

webpack-dev-server seems like is good choice only for people who work with the webpack JS framework. I tried it with webpack-dev-server . and it gives me the following errors:

ERROR in multi (webpack)-dev-server/client?http://localhost:8080 ./
Module not found: Error: Can't resolve '/home/doron/repos/mathrills.com/' in '/home/doron/repos/mathrills.com'
@ multi (webpack)-dev-server/client?http://localhost:8080 ./
webpack: Failed to compile

While searching the internet, it seemed that most of these packages are not meant for static and plain HTML and CSS web pages. I'm not a web applications developer. I just want to write plain HTML and CSS and that's all.

| improve this question | | | | |
  • Well, the only way to do this with HTML pages only and no specific server support is to have the page regularly reload itself on a timer and configure the page so it is not cached by the browser (probably with <meta> tags). Any sort of smart reload that only reloads when the page actually changes on the server will need custom server support for that and will likely need a persistent webSocket connection from web page to server to the browser can be told by the server when to fetch updated content. – jfriend00 Dec 13 '17 at 17:00
1

There was a question about this on StackOverflow several years ago:

Best lightweight web server (only static content) for windows

Options suggested there were:

  1. Mongoose: A small, single executable, embeddable server <- but you'd need to check if it can notice changes to the static files
  2. Use the Python webserver module (i.e. python -m http.server <PORT>) - assuming you can configure it to do what you want
  3. thttpd : A nother very small server; it's man page says it monitors the configuration file for changes, so chances are it also monitors the served files for changes (or simply doesn't cache a copy of them).
  4. nginx or lighttpd: Possibly overkill in terms of features, but nginx is modular and both have small footprints, supposedly.

and there are more...

| improve this answer | | | | |
1

You're talking about something to reload the web browser while you write HTML/CSS right?

webpack-dev-server is perfect for this.

You should be able to find a yeoman generator to set up the right boiler plate for you. But if you're interested, you can just clone a project I have for writing my CV in HTML, which does what you're looking for.

| improve this answer | | | | |
  • First of all, yes, I want it only for pure HTML,CSS and JS. Additionally, I tried webpack-dev-server and I get lot's of errors about unfound modules. I edited the original post. – Doron Behar Dec 15 '17 at 19:47
  • ... Did you run npm install? Getting started with npm/node can be a bit of work at first - as there are a few dependencies that you need to use first. Did you try my github project? – dwjohnston Dec 15 '17 at 21:16
  • Of course I did, I installed webpack and webpack-dev-server with npm install -g. – Doron Behar Dec 20 '17 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.