nicferrier / elnode

evented io webserver right inside your emacs.
http://nicferrier.github.com/elnode
GNU General Public License v3.0
477 stars 49 forks source link

Not a proper issue...but how do you auto refresh browser upon file changes? #102

Open paxperscientiam opened 8 years ago

paxperscientiam commented 8 years ago

Hi uicferrier! First off, thank you for the awesome elnode.

I'm a big fan of emacs and emacs lisps, though I still have much to learn. It's continually exciting to see how extensible emacs really is.

I'm trying to wrap my mind around elnode. One thing in particular that I'm having trouble figuring out is how to auto-refresh the browser (when served files and directories change) with elnode alone (that is, without using additional tools).

Actually, a command would work nicely too when paired with 'firestarter.'

I know that many authors on github don't like "how to" questions, so please do pardon the faux pas.

preetpalS commented 7 years ago

I did not pinpoint how this is done in elnode, but one way to implement this is to inject code (JavaScript) in the client side browser to reload the page when there are filesystem changes. The injected client side code maintains contact (through web sockets or polling) with the server so that it stays informed of any changes on the filesystem. The server either is watching for changes in the filesystem either through polling (constantly checking filesystem on an interval) or through filesystem change events if available (for example via kqueue on FreeBSD). See livereload-js for an example of client side code and middleman-livereload for an example of a corresponding server side implementation.