Skip to content

Commit

Permalink
Merge 8d4d619 into b7b70b8
Browse files Browse the repository at this point in the history
  • Loading branch information
silvenon committed Oct 10, 2020
2 parents b7b70b8 + 8d4d619 commit 8d3760b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/recipes/README.md
Expand Up @@ -28,3 +28,4 @@
* [Rollup with rollup-stream](rollup-with-rollup-stream.md)
* [Run gulp task via cron job](cron-task.md)
* [Running shell commands](running-shell-commands.md)
* [Static asset revisioning](static-asset-revisioning.md)
33 changes: 33 additions & 0 deletions docs/recipes/static-asset-revisioning.md
@@ -0,0 +1,33 @@
# Static asset revisioning

Static asset revisioning by appending content hash to filenames. Make sure to set the files to [never expire](http://developer.yahoo.com/performance/rules.html#expires) for this to have an effect.

```sh
npm install --save-dev gulp gulp-rev gulp-rev-rewrite gulp-rev-delete-original
```

```js
const gulp = require('gulp')
const rev = require('gulp-rev')
const revRewrite = require('gulp-rev-rewrite')
const revDelOriginal = require('gulp-rev-delete-original')

function revisionAssets() {
return gulp
// add assets you want to revision
.src(`dist/**/*.{css,js}`)
// append conent hash
.pipe(rev())
// delete original (unrevved) assets from "dist"
.pipe(revDelOriginal())
// add files that contain references to those assets
// now we have revved assets and HTML files in the stream
.pipe(gulp.src(`dist/**/*.html`))
// update references to the assets
.pipe(revRewrite())
// output revved assets along with HTML files with updated references
.pipe(gulp.dest('dist'))
}

exports.revisionAssets = revisionAssets
```

0 comments on commit 8d3760b

Please sign in to comment.