Skip to content

Instantly share code, notes, and snippets.

@mythmon
Last active October 8, 2015 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mythmon/aa5d0f1fed55aab8fce0 to your computer and use it in GitHub Desktop.
Save mythmon/aa5d0f1fed55aab8fce0 to your computer and use it in GitHub Desktop.
Simple gulp task to cache bust image urls in css.
var gulp = require('gulp');
var cssImageHash = require('gulp-css-image-hash');
gulp.task('images', function() {
return gulp.src('./background.png')
.pipe(gulp.dest('./build/'));
});
gulp.task('css', ['images'], function() {
return gulp.src('./style.css')
.pipe(cssImageHash('build'))
.pipe(gulp.dest('./build/'));
});
gulp.task('default', ['css']);
{
"name": "gulp-demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"gulp": "^3.9.0",
"gulp-css-image-hash": "github:d3r/gulp-css-image-hash#44a0c8108d"
},
"devDependencies": {},
"author": "",
"license": "MIT"
}
body {
background: url('/background.png');
}
@mythmon
Copy link
Author

mythmon commented Oct 1, 2015

The result is build/style.css containining this:

body {
    background: url(/background.png?h=85ae028f5ee9f56909efd3977141ee03);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment