webxl / grunt-reload

A grunt task and reverse proxy that enables live reloading of updated files in the browser.
MIT License
132 stars 19 forks source link

reload randomly not working after successfully trigger watch #11

Open zigotica opened 11 years ago

zigotica commented 11 years ago

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.

cesutherland commented 11 years ago

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?

zigotica commented 11 years ago

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

cesutherland commented 11 years ago

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?

manuel-woelker commented 11 years ago

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/

zigotica commented 11 years ago

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

zigotica commented 11 years ago

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.

cesutherland commented 11 years ago

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 notifications@github.comwrote:

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.

zigotica commented 11 years ago

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