基于gulp的插件,静态资源后面添加时间戳作为版本号,达到去缓存的作用。
npm install gulp-chsi-rev2
var gulp = require('gulp');
var chsiRev = require('gulp-chsi-rev2');
gulp.task('rev',function() {
gulp.src("./test/test.html")
.pipe(chsiRev())
.pipe(gulp.dest('./'));
});
var gulp = require('gulp');
var chsiRev = require('gulp-chsi-rev2');
gulp.task('rev',['revCss'],function() {
gulp.src("./test/test.html")
.pipe(chsiRev({revison: 10000}))
.pipe(gulp.dest('./dest'));
});
gulp.task('revCss',function () {
return gulp.src('./test/styles/test.css')
.pipe(chsiRev(revison: 10000))
.pipe(gulp.dest('./dest/styles/'))
});
gulp.task('default',['rev']);
body{background:url('../images/bg.png')}
body{background:url("../images/bg.png?v=1482737522923")}
<html lang="en">
<head>
<meta charset="utf-8"/>
<title></title>
<link rel="stylesheet" href="./styles/test.css" type="text/css" />
</head>
<body>
<div>
<img src="./images/test.png" />
</div>
<script src="./scripts/test.js" type="text/javascript"></script>
</body>
</html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title></title>
<link rel="stylesheet" href="./styles/test.css?v=1482737522924" type="text/css" />
</head>
<body>
<div>
<img src="./images/test.png?v=148273752295" />
</div>
<script src="./scripts/test1482737522926.js" type="text/javascript"></script>
</body>
</html>