9

Here's a typical workflow:

  1. Edit JS file
  2. Save file, watchify automatically starts rebuilding it for me
  3. alt-tab to browser
  4. ctrl+R to reload page

That's great, except if watchify takes longer than steps 3 and 4, it sucks because you either get the stale code or an error.

Is there an easy way to guarantee that doesn't ever happen? Like a way for watchify to signal to my server that it should wait another split second before trying to load the requested page? If such a thing doesn't exist, how do people deal with this problem in practice?

I must suck at Googling because I can't even find people talking about this problem except this which says "Add a simple (Node-based) server that will block on requests until the watch is done running: this would avoid the always-frustrating phenomenom of reloading the page only to find the watch hasn't quite run yet." -- but unfortunately that's an entry in a todo list, not something that exists in that repo.

dumbmatter
  • 9,351
  • 7
  • 41
  • 80

1 Answers1

4

If you are using Grunt or Gulp you can use the live reload plugin.

Or you can play a beep when the task is complete, so that you know when to reload the page.

Also it may be worth looking at livereloadify.

Emanuele Spatola
  • 555
  • 3
  • 10
  • I'm not using Grunt or Gulp. livereload seems like an interesting concept, but not quite what I want - for instance, sometimes I want to keep the old version of the app running for comparison while I open a new tab to load a version with the changes I just made. That seems like it'd be impossible with livereload. – dumbmatter Nov 21 '15 at 19:22
  • You can create a browserify plugin that emit a beep when the build is completed, otherwise I think the only solution is what you said: "a simple (Node-based) server that will block on requests until the watch is done running" – Emanuele Spatola Nov 21 '15 at 19:34
  • Beep is a non-starter :) yeah I probably could write my own, maybe using a file to mark when watchify is running or not... but I figured there must be somebody who has already done it to save me the trouble! – dumbmatter Nov 21 '15 at 19:41