Skip to content

Commit 8d4d619

Browse files
committed
Docs: Add recipe for static asset revisioning
1 parent b7b70b8 commit 8d4d619

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

docs/recipes/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@
2828
* [Rollup with rollup-stream](rollup-with-rollup-stream.md)
2929
* [Run gulp task via cron job](cron-task.md)
3030
* [Running shell commands](running-shell-commands.md)
31+
* [Static asset revisioning](static-asset-revisioning.md)
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Static asset revisioning
2+
3+
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.
4+
5+
```sh
6+
npm install --save-dev gulp gulp-rev gulp-rev-rewrite gulp-rev-delete-original
7+
```
8+
9+
```js
10+
const gulp = require('gulp')
11+
const rev = require('gulp-rev')
12+
const revRewrite = require('gulp-rev-rewrite')
13+
const revDelOriginal = require('gulp-rev-delete-original')
14+
15+
function revisionAssets() {
16+
return gulp
17+
// add assets you want to revision
18+
.src(`dist/**/*.{css,js}`)
19+
// append conent hash
20+
.pipe(rev())
21+
// delete original (unrevved) assets from "dist"
22+
.pipe(revDelOriginal())
23+
// add files that contain references to those assets
24+
// now we have revved assets and HTML files in the stream
25+
.pipe(gulp.src(`dist/**/*.html`))
26+
// update references to the assets
27+
.pipe(revRewrite())
28+
// output revved assets along with HTML files with updated references
29+
.pipe(gulp.dest('dist'))
30+
}
31+
32+
exports.revisionAssets = revisionAssets
33+
```

0 commit comments

Comments
 (0)