"open or reload" html doc from command line?

I have a program which generates some html documentation. At the end of the script, I use the open command to automatically view the page in the browser.

generate-document > index.html
open index.html

However, after iterating on the code, I end up with numerous obsolete copies of index.html open in my browser.

Is there a way (either from the command line, or within the browser) to say something like "if index.html is already being viewed refresh it, otherwise load it."?

generate-document > index.html
open-or-reload index.html

Safari or Chrome specific methods are fine.


The following command line can be added to your script and it will refresh the Tab that has focus in the frontmost Safari window, (even if the frontmost window only has a single page loaded):

osascript -e \
'tell application "Safari" to set URL of current tab of front window to "file:///foo.html"'

Check out LiveReload. It is an app that watches your HTML files and can automatically for reload the pages in your browser. LiveReload can also do other things like automatically recompile SASS files to CSS and then reload the browser.

In addition to the app at the link above, LiveReload is available on GitHub under a "Open Community Indie Software License" which is not quite open source, but does include a dead man clause to convert to MIT if no new binary updates come out for two years. https://github.com/livereload/LiveReload