question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Browser Sync not injecting/updating styles

See original GitHub issue

I’m using a similar gulpfile to the one on the website. I’m just compiling sass and reloading the styles. The site loads just fine at the BS localhost and IP address, works as it should. Sass compiles but styles don’t update on the sites. Any ideas?

    var gulp        = require('gulp');
    var browserSync = require('browser-sync').create();
    var sass        = require('gulp-sass');

    gulp.task('serve', ['sass'], function() {

    browserSync.init({
        proxy: "rwr.dev"
    });

    gulp.watch("sass/*.scss", ['sass']);
    gulp.watch("*.php, *.js").on('change', browserSync.reload);
    });

     // Compile sass into CSS & auto-inject into browsers
     gulp.task('sass', function() {
    return gulp.src("sass/*.scss")
        .pipe(sass())
        .pipe(gulp.dest("css"))
        .pipe(browserSync.stream());
    });

    gulp.task('default', ['serve']);

It’s a wordpress site running in MAMP if that matters. I have gulp and browser-sync setup inside my theme directory.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:47 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
alxndrmlrcommented, Jan 26, 2016

We just solved this but it was due to a caching issue (we modify the css file names for links and then have an RewriteRule to resolve them)

/**
 *  Given a file, e.g. /css/base.css, replaces it with a string containing the
 *  file's mtime, e.g. /css/base.1221534296.css.
 *  See /app/.htaccess for the server rewrite rule that accompanies this function.
 *
 *  @param $file  The file to be loaded.  Must be an absolute path (i.e.
 *   starting with slash).
 */
function auto_version($file) { ... }

We simply removed our auto_versioning when in development mode and the issues was immediately resolve. While this is unique to our setup I’m mentioning it here so as to encourage others to consider that caching and their app is setup.

In our case the base.css file was being updated during the gulp-task, but since the browser had a <link> to base.1221534296.css it seems that browser-sync wasn’t able to know what css file to sync.

8reactions
Minasokonicommented, May 13, 2016

On El Capitan: Ran: sudo chown -R $(whoami):admin /usr/local The reason BS reloads is because its firing off the generated souremaps. To prevent BS from reloading instead of injecting the CSS, browserSync.stream( {match: '**/*.css' } ) is required

My Code:

var gulp = require( 'gulp' );
var postcss = require( 'gulp-postcss' );
var autoprefixer = require( 'autoprefixer' );
var sass = require( 'gulp-sass' );
var sourcemaps = require( 'gulp-sourcemaps' );
var plumber = require( 'gulp-plumber' );
var notify = require( 'gulp-notify' );
var browserSync = require( 'browser-sync' );
var plumberErrorHandler = {
    errorHandler: notify.onError( {
        title: 'Gulp',
        message: 'Error: <%= error.message %>'
    } )
};
gulp.task( 'browser-sync', function () {
    var files = [
    '../**/*.php',
    '../js/*js'
    ];
    browserSync.init( files, {
        proxy: "localhost",
        notify: true,
        open: false
    } );
} );
gulp.task( 'sass', function () {
    gulp.src( '../sass/**/*.scss' ).pipe( sourcemaps.init() ).pipe( plumber( plumberErrorHandler ) ).pipe( sass() ).pipe( postcss( [ autoprefixer( {
        browsers: [ 'last 2 versions' ]
    } ) ] ) ).pipe( sourcemaps.write() ).pipe( gulp.dest( '../css' ) ).pipe( browserSync.stream( {
        match: '**/*.css' 
    } ) );
} );
gulp.task( 'default', [ 'sass', 'browser-sync' ], function () {
    gulp.watch( "../sass/**/*.scss", [ 'sass' ] );
} );
Read more comments on GitHub >

github_iconTop Results From Across the Web

Browser Sync not refreshing after injecting css - Roots Discourse
The problem I'm having is that browser sync is not refreshing once the new css is injected. Browser sync is working as I...
Read more >
Browser-sync not injecting CSS for remote site - Stack Overflow
I can't host the site locally for development, so I'd rather tweak the CSS locally and see the changes without having to wait...
Read more >
Browsersync options
The UI allows to controls all devices, push sync updates and much more. ... Changes you make will either be injected into the...
Read more >
Browsersync not injecting CSS or JS files [#3086572] - Drupal
Browsersync not injecting CSS or JS files ... Dear Community,. I got a problem with the current implementation of browsersync with laravel-mix.
Read more >
BrowserSync not refreshing - Laracasts
For some reason I can't get BrowserSync to refresh when I update my files. ... the connection gets initialised so BrowserSync is installed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found