0

I am new to Node,grunt and I use both grunt-contrib-watch and grunt-contrib-connect.

As far as I understand, watch task with livereload = true option reruns the mentioned tasks of the target and refreshes the browser by triggering a livereload server to serve reloaded static files.

However, if browser reload and static file serve happens with just watch task with livereload=true option, why do we need grunt-contrib-connect again for the same job.

  • Please explain whether we need connect task still to serve this purpose or is it for something else.
  • Did I understand right with regards to achieving the goal with just watch with livereload=true.

Thanks.

Madav
  • 311
  • 1
  • 5
  • 12

1 Answers1

1

The opetion of livereload in grunt-contrib-watch is responsible to trigger websocket request to browser to reload the page. It is not a http server. From what i remember grunt-contrib-connect is simply an HTTP server. Remember that grunt-contrib-watch starts websocket server at port 35736 so add the script

<script src="//localhost:35729/livereload.js"></script>

To trigger live reload in browser.

Hope this clarifies what you need

georoot
  • 3,557
  • 1
  • 30
  • 59
  • Whenever any css/js files modified, if I can re-run the tasks, reload the files in the server, do a page refresh with just watch with liverreload option and livereload.js in place, then I am not sure what for I need grunt-contrib-connect again? Coz, typically that's what all is needed with regards to static files. Please correct me/clarify. Thank you. – Madav Jan 26 '17 at 14:49
  • @Madav i think what you mean is directly open files in browser, which would work fine i guess. In my cases usually i develop single page applications, so there is some ammount of server routing needed. Thats why the need for `http server`. Not saying it can't be done without it but the proper way is to use server. Also you are not limited to define a server in grunt, i usually end up using a third party server like nginx etc even for my dev code :) – georoot Jan 26 '17 at 14:52
  • Yeah I understand the need for http server.. However, for open static files, is it fare to think that watch-liverreload option alone is sufficient for the job done? Thanks. – Madav Jan 26 '17 at 14:55
  • Yeah sure. But i would recommend a server as that is the final environment that the code is supposed to be served in (y) – georoot Jan 26 '17 at 14:56