grunt-reload icon indicating copy to clipboard operation
grunt-reload copied to clipboard

reload randomly not working after successfully trigger watch

Open zigotica opened this issue 12 years ago • 8 comments

Hi

I have a problem with reload task, it randomly works or not. Here is the relevant parts of my grunt file:

server: {
      port: 8000,
      base: '.'
    },
    reload: {
      port: 6001,
      proxy: {
        host: 'localhost'
      }
    },
    watch:{
      files:['*.html', 'sources/compass/*.scss', 'sources/js/*.js'],
      tasks:'default reload'
    }
  });

  var connect = require('connect');

  // load npm tasks.
  grunt.loadNpmTasks('grunt-contrib-sass');
  grunt.loadNpmTasks('grunt-reload');

  // Register tasks.
  grunt.registerTask('default', 'lint concat min sass');
  grunt.registerTask('live', 'server reload watch');

When i run grunt live sometimes it works perfect, sometimes it does not reload after changes have been made (watch runs ok, but it just fails to reload the browser)

Running "server" task
Starting static web server on port 8000.

Running "reload" task
Proxying http://localhost:8000/
reload server running at http://localhost:6001

Running "watch" task
Waiting...OK
>> File "sources/js/main.js" changed.

Running "lint:files" (lint) task
Lint free.

Running "concat:dist" (concat) task
File "sources/js/app.js" created.

Running "min:dist" (min) task
File "public/js/app.min.js" created.
Uncompressed size: 33387 bytes.
Compressed size: 7243 bytes gzipped (18814 bytes minified).

Running "sass:dist" (sass) task

Running "reload" task
File updated. Reload triggered.

Running "watch" task
Waiting...

As you can see the message for the "reload" task says File updated. Reload triggered. but it does not reload page in browser. Randomly.

I would appreciate any help.

zigotica avatar Oct 18 '12 11:10 zigotica

I experience this if I save multiple times quickly. The first save will refresh the page, and subsequent saves won't. In my case I can see that the websocket is not yet open, and that's why the page does not refresh. Maybe it is the same case for you?

cesutherland avatar Nov 07 '12 20:11 cesutherland

yep, in some cases it does not include de js in the page… weird

zigotica avatar Nov 08 '12 13:11 zigotica

So I see this line in the client code: https://github.com/webxl/grunt-reload/blob/master/tasks/include/reloadClient.js#L48

That 3 second delay is what causes the WS to open late. Any speculation as to why it's there?

cesutherland avatar Nov 17 '12 20:11 cesutherland

Another culprit might be this server side throttling https://github.com/webxl/grunt-reload/blob/master/tasks/reload.js#L61 replacing the throttle with a debounce might do the trick.

cf. http://benalman.com/projects/jquery-throttle-debounce-plugin/

manuel-woelker avatar Dec 21 '12 10:12 manuel-woelker

thank you guys, i'll have a look at both

zigotica avatar Dec 21 '12 11:12 zigotica

thank you @cesutherland and @manuel-woelker Tried what you suggested but I finally quit using the default proxy since it was not creating the websocket whatsoever. Then I installed LiveReload, and now it works like a charm.

zigotica avatar Dec 22 '12 15:12 zigotica

I haven't been having any trouble since removing that timeout. I had a little trouble with the web sockets at first (there are two ports to configure, which was a little confusing).

On Sat, Dec 22, 2012 at 10:18 AM, Sergi Meseguer [email protected]:

thank you @cesutherland https://github.com/cesutherland and @manuel-woelker https://github.com/manuel-woelker Tried what you suggested but I finally quit using the default proxy since it was not creating the websocket whatsoever. Then I installed LiveReload, and now it works like a charm.

— Reply to this email directly or view it on GitHubhttps://github.com/webxl/grunt-reload/issues/11#issuecomment-11638042.

cesutherland avatar Dec 22 '12 15:12 cesutherland

@cesutherland been trying what you guys suggested, in all combinations, with no luck, that's why i finally installed LiveReload. Thanx again, anyway.

zigotica avatar Dec 22 '12 15:12 zigotica