A simple live-reload implementation that refreshes the page when the source file changes on disk.
The server.js file just serves the files in the directory that
it is in, including itself. It also ensures that a private
Cache-Control header is set for GET requests, and
caching disabled for other HTTP methods.
The index.html file contains a hand-rolled live-reload script
that polls the server every 2 seconds and honors the HTTP 304
response code and the caching and etag directives specified by
the server.
This can also run as a zero-dependency implementation of live-reload by removing JQuery and Express from the example code and using plain JavaScript DOM methods and the built-in Node.js HTTP server.
Run the server with:
node server.jsEdit the index.html file and watch the page reload only when the file changes.
Check the browser log and network console to see what's going on under the
hood.