Skip to content

Generates checksums and renames references to files, useful for cachebusting

Notifications You must be signed in to change notification settings

Josiah/gulp-cachebust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gulp-cachebust

Generates checksums and renames references to files

Useful for cachebusting

Install

Install with npm

npm install --save-dev gulp-cachebust

Example

var gulp = require('gulp');
var CacheBuster = require('gulp-cachebust');

var cachebust = new CacheBuster();

gulp.task('build-css', function () {
    return gulp.src('styles/*.css')
        // Awesome css stuff
        .pipe(cachebust.resources())
        .pipe(gulp.dest('dist/css'));
});

gulp.task('build-html', ['build-css'], function () {
    return gulp.src('templates/*')
        // Awesome html stuff
        .pipe(cachebust.references())
        .pipe(gulp.dest('dist'));
});

API

new CacheBuster(options)

options.checksumLength

Optional

Type: Number Default: 8

options.random

Generates the checksum based on a random sha1 hash and not on the file contents.
Useful for changing the file names on each deploy regardless if the content was changed or not.

Optional

Type: Boolean Default: false

options.pathFormatter

Specify a custom formatting function for busted paths. The default will output filenames like /path/to/basename.[hash].ext.

Optional

Type: Function Default: null

An example for outputing a custom hash prefix:

{
    pathFormatter: function(dirname, basename, extname, checksum) {
        return require('path').join(dirname, basename + '._v' + checksum + extname);
    }
}

CacheBuster.resources()

Renames and collects resources according to their MD5 checksum.

CacheBuster.references()

Rewrites references to resources which have been renamed according to their MD5 checksum.

License

MIT © Josiah Truasheim

About

Generates checksums and renames references to files, useful for cachebusting

Resources

Stars

Watchers

Forks

Packages

No packages published