GitHub - talwrii/inotify_httpd: Serve files over HTTP; immediately refresh brows...
source link: https://github.com/talwrii/inotify_httpd
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
inotify_httpd
Serve files over HTTP; immediately refresh browsers when the files change on disk.
This is achieved using Linux's inotify system calls, JavaScript, WebSockets, and an HTML iframe.
This tool requires Python 3 (but can happily coexist with Python 2). Requires Linux (or a system with inotify
system calls).
Usage
# Serve a single file on port 10000
# ( a WebSocket port is opened on 10001)
inotify_httpd /tmp/file.html
# Serve a directory on port 10000
inotify_httpd /tmp/www
Installation
# Ensure pip3 is install
sudo apt-get install python3-pip
# release version
pip3 install inotify_httpd
# latest development version
pip3 install git+https://github.com/talwrii/inotify_httpd#egg=inotify_http
Caveats
-
Content is served by a JavaScript wrapper, so may not interact very well with tools like
curl
. -
The browser's URLs are not updated when following links, due to the
iframe
wrapper -
Only tested with Firefox.
-
The actions that cause refresh could be a lot more targeted: changing an unrelated but watched file may result in a browser refresh.
-
There are no automated tests of behaviour.
Alternatives and prior work
- Browsersync is a Node.Js framework that provides a similar utility. It provides a command line utility that has similar features:
browser-sync --server --files '.'
. - There are many browser extensions that will periodically refresh a web-page. These refreshes may create visual artefacts (unless some form of "render caching" is used) and one must trade-off the polling rate against responsiveness.
- bcat is a utility that can feed bash pipe-line output into the browser and refresh. This can result in a large number of open tabs and does not interact well with multiple browser profiles. Nevertheless,
while true; do inotifywait /tmp/file ; bcat /tmp/file; done
may be a good alternative to this tool. - This question on StackOverflow addresses a similar topic.
- LiveJs is an in-code / bookmarklet solution that works by continually polling with HEAD requests. This will dynamically apply CSSs.
- reload is an Node.js command-line program that supports a very similar mode of execution. This is achieved through filesystem polling by executing a script called supervisor. Depending on the poll rate this may result in delays or moderate resource usage.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK