Go to file
John Bintz 81a14b4357 Merge pull request #43 from swrobel/master
Fix typo in .travis.yml to prevent Rails 4 building on Ruby < 1.9.3
2013-08-22 18:36:05 -07:00
features a little cleanup, add cucumber, add support for ignoring particular browsers 2012-01-03 08:58:51 -05:00
gemfiles Test on Ruby 2 && Rails 4 2013-08-20 15:56:47 -07:00
js Adds the live_reload_port option. 2013-02-03 22:46:38 +11:00
lib Skip processing for non-GET requests 2013-08-20 13:55:47 -07:00
skel a little more code shuffling to clean up the body processor class a bit 2013-05-06 09:36:15 -04:00
spec Skip processing for non-GET requests 2013-08-20 13:55:47 -07:00
.gitignore Remove appraisal lock files to fix travis 2013-08-20 14:30:18 -07:00
.travis.yml Fix typo in .travis.yml to prevent Rails 4 building on Ruby < 1.9.3 2013-08-21 23:57:55 -07:00
Appraisals Test on Ruby 2 && Rails 4 2013-08-20 15:56:47 -07:00
Gemfile initial commit 2011-11-04 11:51:22 -04:00
Guardfile remove deprecated rspec option from guardfile 2012-12-13 14:49:15 -08:00
LICENSE add license, fixes #14 2012-10-12 18:42:22 -04:00
README.md add code climate badge, since we're starting to be more awesome in that regard 2013-04-30 10:07:23 -04:00
Rakefile Appraisals and travis 2012-05-30 19:47:31 +03:00
config.ru ensure you're actually working with real lines, not assuming the return value is an array you can mutate, fixes #6 2012-03-02 09:25:48 -05:00
index.html a little cleanup, add cucumber, add support for ignoring particular browsers 2012-01-03 08:58:51 -05:00
rack-livereload.gemspec Set max Nokogiri version for development on Ruby 1.8 2013-08-20 14:46:09 -07:00

README.md

Code Climate

Hey, you've got LiveReload in my Rack! No need for browser extensions anymore! Just plug it in your middleware stack and go! Even supports browsers without WebSockets!

Use this with guard-livereload for maximum fun!

Install

gem install rack-livereload

Using in...

Rails

In config/environments/development.rb:

MyApp::Application.configure do
  config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload)

  # ...or, change some options...

  config.middleware.insert_before(
    Rack::Lock, Rack::LiveReload,
    :min_delay => 500,
    :max_delay => 10000,
    :port => 56789,
    :host => 'myhost.cool.wow',
    :ignore => [ %r{dont/modify\.html$} ]
  )
end

config.ru/Sinatra

require 'rack-livereload'

use Rack::LiveReload
# ...or...
use Rack::LiveReload, :min_delay => 500, ...

How it works

The necessary script tag to bring in a copy of livereload.js is injected right after the opening head tag in any text/html pages that come through. The script tag is built in such a way that the HTTP_HOST is used as the LiveReload host, so you can connect from external machines (say, to mycomputer:3000 instead of localhost:3000) and as long as the LiveReload port is accessible from the external machine, you'll connect and be LiveReloading away!

Which LiveReload script does it use?

  • If you've got a LiveReload watcher running on the same machine as the app that responds to http://localhost:35729/livereload.js, that gets used, with the hostname being changed when injected into the HTML page.
  • If you don't, the copy vendored with rack-livereload is used.
  • You can force the use of either one (and save on the cost of checking to see if that file is available) with the middleware option :source => :vendored or :source => :livereload.

How about non-WebSocket-enabled browsers?

For browsers that don't support WebSockets, but do support Flash, web-socket-js is loaded. By default, this is done transparently, so you'll get a copy of swfobject.js and web_socket.js loaded even if your browser doesn't need it. The SWF WebSocket implementor won't be loaded unless your browser has no native WebSockets support or if you force it in the middleware stack:

use Rack::LiveReload, :force_swf => true

If you don't want any of the web-sockets-js code included at all, use the no_swf option:

use Rack::LiveReload, :no_swf => true

Once more browsers support WebSockets than don't, this option will be reversed and you'll have to explicitly include the Flash shim.