Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Gulp to add a timestamp to filename

Using Gulp I've got a pretty simple build process which compresses everything into styles.min.css

gulp.task( 'styles', function() {
    gulp.src( './scss/*.scss' )
    .pipe( sass( { errLogToConsole: true } ) )
    .pipe( autoprefix( 'last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4' ) )
    .pipe( cssmin() )
    .pipe( rename( 'styles.min.css' ) )
    .pipe( gulp.dest( '../dist' ) );
});

Can I modify this to append a timestamp to the file name, so my browser knows this is a new file and to clear its cache?

Something like this:

styles—1423267988.min.css

like image 531
Rich Avatar asked Dec 11 '22 01:12

Rich


1 Answers

Follow-up:

Apparently, this is called cache-busting or fingerprinting

Using gulp-rev will append a hash to your output file.

...
    .pipe( rev() )
    .pipe( gulp.dest( '../dist' ) );
});
like image 73
Rich Avatar answered Jan 01 '23 09:01

Rich