Skip to content

Commit

Permalink
Docs: Add recipe for static asset revisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
silvenon committed Oct 10, 2020
1 parent b7b70b8 commit 8d4d619
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 8d4d619

Please sign in to comment.