Invalidating cache by appending hash in file name
This plugin requires Grunt ~0.4.5
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-cache-invalidate --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-cache-invalidate');
In your project's Gruntfile, add a section named cache_invalidate
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
cache_invalidate: {
your_target: {
src: ['sample.html', ...],
dest: 'build'
}
},
});
Now it will recursively resolve your referrences between files and will break the circuler reference.
move - true deletes the resource src files
grunt.initConfig({
cache_invalidate: {
your_target: {
src: ['sample.html', ...],
dest: 'build',
move: false
}
},
});
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<script type="text/javascript" src="sample1.js#grunt-cache-invalidate"></script>
<script type="text/javascript" src="sample2.js#grunt-cache-invalidate"></script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<script type="text/javascript" src="sample1.5340dc1df.js"></script>
<script type="text/javascript" src="sample2.e7d97adc3.js"></script>
</head>
<body>
</body>
</html>
And sample1.5340dc1df.js
, sample2.e7d97adc3.js
should be in your dest folder.
2014.06.19 - v0.01.0