<header>
    <h3>Redis Log</h3>
</header>
<textarea id="logger" style="width: 100%;" rows="20" cols="50" readonly="true"></textarea>

<script>
  var show_logs_for = function(event_channel, event_id, log_id) {

    if (!!window.EventSource) {
      source = new EventSource(event_channel); // match routes.rb

      element = document.getElementById(log_id); // match template

      source.addEventListener(event_id, function(e) {
        //firefox has no 'data'
        if (e.data) data = e.data; else data = e;

        element.innerHTML += data + "\n";
        element.scrollTop = element.scrollHeight;
      });
    }
    else {
      // Result to xhr polling :(  TODO
    }
  };

  show_logs_for('/sidekiq/redis_log_stream', 'redis_log', 'logger')

</script>

<header>
    <h3>Redis Log</h3>
</header>
<textarea id="logger" style="width: 100%;" rows="20" cols="50" readonly="true"></textarea>

<script>
  var show_logs_for = function(event_channel, event_id, log_id) {

    if (!!window.EventSource) {
      source = new EventSource(event_channel); // match routes.rb

      element = document.getElementById(log_id); // match template

      source.addEventListener(event_id, function(e) {
        //firefox has no 'data'
        if (e.data) data = e.data; else data = e;

        element.innerHTML += data + "\n";
        element.scrollTop = element.scrollHeight;
      });
    }
    else {
      // Result to xhr polling :(  TODO
    }
  };

  var stream_path = document.location.pathname + '_log_stream';
  show_logs_for(stream_path, 'redis_log', 'logger')

</script>

Use calculated relative URL based on currents document path
Use calculated relative URL based on currents document path

Sometimes people don't want to mount the Sidekiq WebGUI directly under /sidekiq, so we should calculate the stream path based on the current document's path.