Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use livereload from multiple servers in a single page? (in particular with Grunt.js connect and watch)

I am trying to get livereload working in one website, triggered by different servers, from different projects. I am using Grunt.js with grunt-contrib-connect and grunt-contrib-watch.

Here is an example:

  • ProjectA is currently running a livereload server on localhost:33333
  • ProjectB is currently running a livereload server on localhost:44444
  • ProjectC is currently running a livereload server on localhost:55555

Now let's say, I run a webpage on localhost:9800 that should benefit from livereloading So, in most cases where only one livereload process is present, one would have something like this in localhost:9800/index.html :

 
<body>
  ...
  <script type="text/javascript" charset="UTF-8" src="//localhost:35729/livereload.js"></script>
</body>
 

so, with multiple livereload servers, I thought I'd have to include all livereload scripts:

 
<body>
...
  <script type="text/javascript" charset="UTF-8" src="//localhost:33333/livereload.js"></script>
  <script type="text/javascript" charset="UTF-8" src="//localhost:44444/livereload.js"></script>
  <script type="text/javascript" charset="UTF-8" src="//localhost:55555/livereload.js"></script>
</body>
 

which is not working. Only the first script will trigger livereload in the browser. In the docs of grunt-contrib-watch, they have an example about running different servers in different targets of the watch task. How do you actually make this work?

Thank you for any help

Here is my watch task for testing:

 
  watch: {

    css: {
      files: ['www/**/*.css'],
      options: {
        livereload: 33333
      }
    },

    html: {
      files: ['www/**/*.html'],
      options: {
        livereload: 44444
      }
    },

    js: {
      files: ['www/**/*.js'],
      options: {
        livereload: 55555
      }
    },
...
}
like image 278
Kev Avatar asked Oct 14 '25 12:10

Kev


1 Answers

This configuration could not work.

livereload.js instantiates a global object LiveReload see ( livereload-js/src/startup.coffee ). And there is only one web-socket available per LiveReload object, so you could not have on 3 sockets.

I would like to have the same configuration as you, but today I do not find a work around for it

like image 189
duckmole Avatar answered Oct 18 '25 00:10

duckmole