-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs: Add recipe for static asset revisioning
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |