Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple files changed = multiple reloads. Global debounce? #329

Closed
fregante opened this issue Nov 14, 2014 · 9 comments · May be fixed by tobybellwood/govstrap#4
Closed

Multiple files changed = multiple reloads. Global debounce? #329

fregante opened this issue Nov 14, 2014 · 9 comments · May be fixed by tobybellwood/govstrap#4

Comments

@fregante
Copy link

My gulp workflow sometimes will yield multiple html files (e.g. I change a Jade partial and 3 dependent files are regenerated) within 1-2 seconds. This cause BS to reload as many times as the number of files, sometimes actually missing the last one (incidentally exactly the one I have open in the browser).

Is there a way to debounce these refreshes? Ideally it should happen either:

  • _.debounce(refresh, 1000), a second after the last file changes, or
  • _.debounce(refresh, 1000, {leading:true}), as soon as the first file changes and a second after the last file changes
@fregante
Copy link
Author

Ah, I just found #134 and that's actually better! I excluded html files from browserSync and added browserSync.reload to my watch task:

var gulp  = require('gulp');
var browserSync = require('browser-sync');
var dest = './dist';

gulp.task('browserSync', function() {
  browserSync({
        files: [
            dest + '/**',
            '!' + dest + '/**/*.html'
        ]
    });
});
gulp.task('watch', ['browserSync'], function() {
  gulp.watch(config.markup.src, ['html', browserSync.reload]);
});

I was afraid I would have to .pipe() that reload function after each task, but this is a lot better

@fregante
Copy link
Author

Actually, this has become an issue again since I started using BS from the command-line. I googled for a solution and ended up back on this issue :D

@fregante fregante reopened this Feb 19, 2015
@shakyShane
Copy link
Contributor

Small sample project highlighting the issue? :)

@shinnn
Copy link
Contributor

shinnn commented Mar 18, 2015

@bfred-it Any updates?

@fregante
Copy link
Author

This is a sample project that simulates the behavior with gulp while launching BS from CLI:
DOWNLOAD

Keep in mind that I wouldn't be able to solve the issue it like I did in my second post (i.e. within gulp itself)

gulp # in separate window
browser-sync start --server --files "dist/*.html"  --startPath "dist/a.html"

Demo. Notice how the timestamp changes 3 times

demo

@shakyShane
Copy link
Contributor

@bfred-it - thanks!

File watching is undergoing a rewrite currently so we'll make sure this is fixed also :)

@fregante
Copy link
Author

Woot!

@shakyShane
Copy link
Contributor

2.6.0 has reload-delay & reload-debounce available on the CLI

@CYFERIOUS
Copy link

hey my browsersync is reloading every 43 ms, its impossible to work , some help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants