BrowserSync / browser-sync

Keep multiple browsers & devices in sync when building websites. https://browsersync.io
https://discord.gg/2d2xUThp
Apache License 2.0
12.16k stars 755 forks source link

Doesn't work if whitespace before doctype #1299

Open ghost opened 7 years ago

ghost commented 7 years ago

Issue details

Browsersync doesn't seem to work if there is any whitespace before the doctype. The snippet never gets loaded and no errors in the console, using the proxy feature.

Steps to reproduce/test case

Proxy to a page which has whitespace before the doctype.

Please specify which version of Browsersync, node and npm you're running

Affected platforms

Browsersync use-case

for all other use-cases, (gulp, grunt etc), please show us exactly how you're using Browsersync

gulp.task('watch', function() {

    // Javascipt
    browserSync.watch(config.paths.javascript.src + "/**/*.js", function(event, file) {

        if(event === "change") {
            var pathArray = file.split('/');
            javascriptTask(pathArray[5]);
        }
    });

    // CSS
    browserSync.watch(config.paths.styles.src + "/**/*.scss", function(event, file) {

        if(event === "change") {
            var pathArray = file.split('/');
            cssTask(pathArray[5]);
        }
    });

    // Images
    watch(config.paths.images.src + "/**/*", function() {
        gulp.start('images');
    });

    // HTML
    watch(config.paths.templates + "/**/*", function(event) {

        if(event === "change") {
            browserSync.reload();
        }
    });

    // Browsersync
    browserSync.init({
        files: [
            config.paths.javascript.dist,
            config.paths.styles.dist,
            config.paths.images.dist,
            config.paths.templates
        ],
        proxy: config.url
    });
});
codep0et commented 6 years ago

+1 here, after 3 hours of debugging, realized my wordpress template file was outputting a new line before the doctype.

Even trying to switch around snipperOptions to change the regex to something else than body didnt work.