Versions your appcache manifest files with a checksum based on the contents of your CACHE header
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-appcache-versioner --save-devOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-appcache-versioner');In your project's Gruntfile, add a section named appcache_versioner to the data object passed into grunt.initConfig().
grunt.initConfig({
appcache_versioner: {
manifests: {
src: ["**/*.manifest", "**/*.appcache"],
dest: "."
},
},
});You might be wondering how the checksum is generated. This plugin iterates over all the files located in your CACHE header and creates a sha1 hash of their contents. This ensures that your appcache manifest file changes each time a file it's responsible for changes.
This describes a common use case: simply adding a version to your currently existing manifest files.
grunt.initConfig({
appcache_versioner: {
manifests: {
src: ["**/*.manifest", "**/*.appcache"],
dest: "."
},
},
});Let's say you have the following cache manifest file in the root directory of your project:
CACHE MANIFEST
#Version 1.0.0
CACHE:
some/file.html
some/other/script.js
NETWORK:
*
FALLBACK:
#No fallbacks
Running the above configuration will overwrite this file with the following:
CACHE MANIFEST
#ea91533aa7cebc582decb5c7c7ba573b3d7ebc2e
CACHE:
some/file.html
some/other/script.js
NETWORK:
*
FALLBACK:
#No fallbacks
Note by changing the dest property of your target the file will be written to the dest directory. For example, with dest: "build" your versioned manifest file will end up in build/example.manifest, leaving the original intact. The file structure is preserved, so if you had some/dir/example.manifest it would appear as build/some/dir/example.manifest
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
April 16, 2015 Released initial version of the plugin.