Note: This modules does nothing with the file system, that means you'll have to read/write files yourself, or wait for the Grunt & Gulp Plugins
npm install cache-breaker
var cacheBreaker = require("cache-breaker");
Append a timestamp as query string
var string = '<link href="https://github.com/shakyShane/cache-breaker/blob/master/style.css" /><link href="https://github.com/shakyShane/cache-breaker/blob/master/style2.css" />';
cacheBreaker.breakCache(string, ['style.css', 'style2.css']);
// output
// <link href="https://github.com/shakyShane/cache-breaker/blob/master/style.css?rel=23452341" /><link href="https://github.com/shakyShane/cache-breaker/blob/master/style2.css?rel=23452341" />
Append a timestamp in the filename
var string = '<link href="https://github.com/shakyShane/cache-breaker/blob/master/style.css" />';
cacheBreaker.breakCache(string, 'style.css', {position: 'filename'});
// output
// <link href="https://github.com/shakyShane/cache-breaker/blob/master/style.56432352.css" />
Overwrite an exiting timestamp
Use this when you have rewrite rules in place.
var string = '<link href="https://github.com/shakyShane/cache-breaker/blob/master/style.2452345.css" />';
cacheBreaker.breakCache(string, 'style.*.css', {position: 'overwrite'});
// output
// <link href="https://github.com/shakyShane/cache-breaker/blob/master/style.56432352.css" />