0

I am using gulp-rev to cache-bust my compiled scss files. This means the css injections works only when I don't change anything in my css file. If I change anything, gulp-rev will give the file a different name and browserSync won't know to inject it. Here is the scss task in my gulpfile:

Object.keys(styles).forEach(function(key){
    gulp.task('css-' + key, function(){
        del.sync([
            './public/' + styles[key].dir +  manifest[key + '.css'],
            './public/' + styles[key].dir + '/maps/' + manifest[key + '.css'] + '.map'
        ]);
        return gulp.src('./source/' + styles[key].dir + key + '.scss')
            .pipe(plumber())
            .pipe(sourcemaps.init())
            .pipe(sass())
            .pipe(minifycss())
            .pipe(autoprefixer())
            .pipe(rev())
            .pipe(sourcemaps.write('maps/'))
            .pipe(tap(updateManifest))
            .pipe(gulp.dest('public/' + styles[key].dir))
            .pipe(gulpif(
                function(file){return path.extname(file.path) === '.css'},
                browsersync.stream()
            ));
    });
});

1 Answer 1

1

I believe in general you shouldn't be doing revisions during the development process. If you're worried about cache busting usually it shouldn't be a problem and you can always hard reload. However, you can also configure your local dev server to set the max-age to 0 or set the header Cache-Control: no-cache.

You should have a separate gulp task for your distribution (or apply rev only when building a dist version).

Sign up to request clarification or add additional context in comments.

1 Comment

I solved this a while ago by having a css-* task with no cache busting for development and a build-css-* task with cache busting for production. The former is injected with browser-sync.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.