I sometimes want to use LiveReload to automatically refresh index.html when I'm working on some JavaScript. Yes, you can use the $10 app, but I generally end up using Guard anyway for compiling CoffeeScript or SCSS, and I dislike browser plugins because of the security risks. Turns out that it's pretty easy to get LiveReload working with Guard and Rack sans plugins.
The code is in a Gist below. All files go in a single folder (say, ~/git/myproject
). To run it (after bundle install
ing), open two Terminal tabs in this folder. In the first one, run guard
. In the other, run ruby serve.rb
. Then hit up http://localhost:4567 in your browser of choice. LiveReload should automatically reload the page when you change index.html
(as configured; modify the Guardfile to watch additional files for changes).
(These instructions are a little vague, because if you can't easily fill in the blanks you should probably just use the app. It's not worth learning all about Ruby/Gems/Rack/Guard to save $10.)
🌟 Was this page helpful? Please let me know with this quick, 3 question survey.