gulp-uncache
Append unique string or md5 hash to paths in html files to force refresh - remove users cache app.js -> app_8j3d7a4f.js
Supported script and link tags with src
or href
attributes.
Install
$ npm install --save-dev gulp-uncache
Effect
Before:<!-- uncache --><!-- enduncache --> <!-- uncache(rename:true, append:hash, srcDir:src, distDir:dist) --><!-- enduncache --> After:
Options
append
Type String
default: time
String to append or one from:
time
- append actual time stamp
hash
- append md5 hash of file (prevent unnecessary refreshing file) need correct srcDir & distDir
rename
Type Boolean
default: false
If set to true rename file otherwise append string as url query string
srcDir
Type String
default: ./
Path to dir with source files. (Used only when
rename:true
, orappend:'hash'
)
distDir
Type String
default: ./
Path to dir where renamed files will be saved. (Used only when
rename:true
)
template
Type String
default {{path}}{{name}}_{{append}}.{{extension}}
Template for replace (Hogan.js). Available variables:
path
,name
,append
,extension
srcFileMap
Type Function
Parameters: fileName
Function for transforming src file path At default returns
path.join(config.srcDir, fileName);
Inline options
You can set options inline that way: (omit quotes sign)
<!-- uncache(param:value, param:value) -->
Examples
Basic
gulpfile.js
var gulp = ;var uncache = ; gulp;
src/index.html
<!--uncache--> <!--enduncache--> <!--uncache(rename:false)--> <!--enduncache-->
dist/index.html
With other plugins
gulpfile.js
var gulp = ;var usemin = ;var uncache = ; gulp;
src/index.html
<!--uncache--><!-- build:js lib.js --><!-- endbuild --><!--enduncache-->
dist/index.html
To do
- 'uncache' for all sources in files without
<!--uncache-->
tags - support css images (e.g. for often changing css sprites image)
Changelog
0.4.0-beta1
0.2.3
- option template
0.2.2
- inline options
- fixed parsing regexp
0.2.0
- option rename
- option append hash
- allow both
'
and"
in tags
0.1.3
- added append option
0.1.2
- fixed multi line blocks
- fixed parsing lines with attributes
- skipping incorrect tags
- log info and errors
0.1.1
- initial release
License
MIT © Maciej Dudziński