Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

gulp-cachebust

jhuesos5.2kMIT0.0.11

Generates checksums and renames references to files, useful for cachebusting

readme

gulp-cachebust

Generates checksums and renames references to files

Travis build status Dependency status MIT Licence

Useful for cachebusting

This plugin is only compatible with files that contain a stream, it only works in buffer mode.

This is the new repository for gulp-cachebust plugin. The plugin was originaly created by Josiah Truasheim and it has been transfered to this new repository (link to the previous one). Development will continue in this repository.

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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[Unreleased]

[0.0.10] - 2018-02-28

Changed

  • Removed usage of gulp-util. (thanks @tuxlife)

[0.0.9] - 2017-10-28

Changed

  • Escape Regex special chars from original path. Fixes #3 (thanks @jaysalvat)

[0.0.8] - 2017-08-11

Changed

  • This plugin does not work with files containing a stream (gulp.src(..., {buffer: false});). So the plugin has been changed so when passed file with streams it throws and error.

[0.0.7] - 2017-08-10

Added

  • CHANGELOG.md, .editorconfig and other files to improve project structure and consistency.

Changed

  • Moved to a new Github repository.
  • Missing metadata in the package.json has been added.

[0.0.11] - 2019-09-16

Fixed

  • Path to substitute are now sorted by from longest to shortest. (Fixes #10). Thanks @EdTorbett for your help!.

Changed

  • Updated Mocha to its latest version as it contained critical security vulnerability.