# gulp-cachebust

> Generates checksums and renames references to files, useful for cachebusting

Latest version **0.0.11** (published 2019-09-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-cachebust
pnpm add gulp-cachebust
yarn add gulp-cachebust
bun add gulp-cachebust
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2019-09-16 |
| First published | 2014-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0 |
| Dependencies | 3 |
| Unpacked size | 12.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Josiah |
| Maintainers | jhuesos, josiah |

## Links

- npm: https://www.npmjs.com/package/gulp-cachebust
- Repository: https://github.com/jhuesos/gulp-cachebust
- Homepage: https://www.npmjs.com/package/gulp-cachebust
- Issues: https://github.com/jhuesos/gulp-cachebust/issues
- npm.io page: https://npm.io/package/gulp-cachebust

## Dependencies (3)

- [slash](https://npm.io/package/slash.md) 1.0.0
- [through2](https://npm.io/package/through2.md) ^0.5.1
- [plugin-error](https://npm.io/package/plugin-error.md) ^1.0.1

## Recent versions

- 0.0.11 (latest) — 2019-09-16
- 0.0.10 — 2018-02-28
- 0.0.9 — 2017-10-28
- 0.0.8 — 2017-08-11
- 0.0.7 — 2017-08-10
- 0.0.6 — 2015-08-28
- 0.0.5 — 2014-12-30
- 0.0.4 — 2014-12-10
- 0.0.3 — 2014-07-25
- 0.0.2 — 2014-03-21
- 0.0.1 — 2014-03-21

## README

# [gulp](https://github.com/wearefractal/gulp)-cachebust

> Generates checksums and renames references to files


![Travis build status](https://travis-ci.org/jhuesos/gulp-cachebust.svg?branch=master)
![Dependency status](https://david-dm.org/jhuesos/gulp-cachebust.svg)
![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)

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](https://github.com/Josiah/gulp-cachebust) to the previous one). 
Development will continue in this repository. 

## Install

Install with [npm](https://npmjs.org/package/gulp-cachebust)

```
npm install --save-dev gulp-cachebust
```

## Example

```js
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:

```js
{
    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](//github.com/Josiah)

---
_Source: https://npm.io/package/gulp-cachebust · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
