Gulp: Browser reloads before code was syncing
See original GitHub issueHi, sometimes i have this issue with BrowserSnc + Gulp: the Browser reloads before the code is synced.
Here my typical gulpfile:
var gulp = require('gulp');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var cssnext = require('cssnext');
var precss = require('precss');
var dirSync = require('gulp-directory-sync');
var browserSync = require('browser-sync').create();
gulp.task('css', function () {
var processors = [
autoprefixer,
cssnext,
precss
];
return gulp.src('./src/*.css')
.pipe(postcss(processors))
.pipe(gulp.dest('./build'));
});
gulp.task('sync', function () {
return gulp.src('src')
.pipe(dirSync('src', 'build', {ignore: ['stuff', 'css']}, 'nodelete'));
});
gulp.task('browserSync', function () {
browserSync.init({
proxy: "webwork/clients/wordpress/website"
});
});
gulp.task('default', ['browserSync'], function () {
gulp.watch('src/*.css', ['css']).on('change', browserSync.reload);
gulp.watch('src/**/*.php', ['sync']).on('change', browserSync.reload);
});
After the second change in code, the reload will start before syncing. This makes the changes only visible after the next change/relaod…
Only this workaround works:
gulp.task('browserSync', function () {
browserSync.init({
reloadDelay: 1000,
proxy: "webwork/clients/wordpress/website"
});
});
If i use the reloadDelay option. Only this will make the Browser reloading after syncing.
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
node.js - Browsersync with gulp refreshing before finished
Now, whenever there is a change in my code, my "some-task-name" gets executed and then the browser page is reloaded. I don't need...
Read more >Gulp.js browser-sync not reloading my browser #1489 - GitHub
When I hit save on my project it builds everything fine. My browser blinks and says "Connected to Browser-sync" on the upper right...
Read more >How To Use Gulp - Browser Sync Live Reload Tutorial
In this video I show you How To Use BrowserSync to Live Reload your Web Browser whenever you make changes to your code....
Read more >Gulp from Scratch: Browser-Sync Auto Reload HTTPS
Support Me ::https://www.patreon.com/alecadddhttp://www.alecaddd.com/support-me/https://amzn.to/2Hcp5moCheck out Elementor: ...
Read more >Browsersync + Gulp.js
Browsersync makes your browser testing workflow faster by synchronising URLs, interactions and code changes across multiple devices.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
One other thing to look at: make sure all of the tasks that compile code return the task result (promise).
In other words, make sure this:
Becomes:
This helps ensure that BrowserSync is only invoked when the compilation “promise” is resolved.
Thank you GuyPaddock. return keyword…! that is it…!