Generate HTML5 Cache Manifest files. Submitted by Gunther Brunner.
This plugin requires Grunt ~0.4.0
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-manifest --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-manifest');
Run this task with the grunt manifest
command.
Visit the Appcache Facts for more information on Cache Manifest files.
Task targets, files and options may be specified according to the grunt Configuring tasks guide.
Type: Object
Default: {}
This controls how this task (and its helpers) operate and should contain key:value pairs, see options below.
Type: String
Array
Default: undefined
Sets the input files.
Type: String
Default manifest.appcache
Sets the name of the Cache Manifest file.
Remember that .appcache
is now the W3C recommended file extension.
Type: String
Default: undefined
Sets the base path for input files. It's recommended to set this.
Type: String
Default: undefined
Adds manually a string to the CACHE section. Needed when you have cache buster for example.
Type: String
Array
Default: undefined
Exclude specific files from the Cache Manifest file.
Type: String
Array
Default: "*"
(By default, an online whitelist wildcard flag is added)
Adds a string to the NETWORK section.
See here for more information.
Type: String
Array
Default: undefined
Adds a string to the FALLBACK section.
See here for more information.
Type: Boolean
Default: undefined
Adds a string to the SETTINGS section, specifically the cache mode flag of the prefer-online
state.
See here for more information.
Type: Boolean
Default: true
Adds a meta "copyright" comment.
Type: Boolean
Default: true
Adds a timestamp as a comment for easy versioning.
Note: timestamp will invalidate application cache whenever cache manifest is rebuilt, even if contents of files in src
have not changed.
Type: Boolean
Default: false
Adds a sha256 hash of all src
files (actual contents) as a comment.
This will ensure that application cache invalidates whenever actual file contents change (it's recommented to set timestamp
to false
when hash
is used).
Type: String
Array
Default: undefined
Hashes master html files (used with hash
). Paths must be relative to the 'basePath'. This is useful when there are multiple html pages using one cache manifest and you don't want to explicitly include those pages in the manifest.
// Project configuration
grunt.initConfig({
manifest: {
generate: {
options: {
basePath: '../',
cache: ['js/app.js', 'css/style.css'],
network: ['http://*', 'https://*'],
fallback: ['/ /offline.html'],
exclude: ['js/jquery.min.js'],
preferOnline: true,
verbose: true,
timestamp: true,
hash: true,
master: ['index.html']
},
src: [
'some_files/*.html',
'js/*.min.js',
'css/*.css'
],
dest: 'manifest.appcache'
}
}
});
CACHE MANIFEST
# This manifest was generated by grunt-manifest HTML5 Cache Manifest Generator
# Time: Mon Jan 01 2155 22:23:24 GMT+0900 (JST)
CACHE:
js/app.js
css/style
css/style.css
js/zepto.min.js
js/script.js
some_files/index.html
some_files/about.html
NETWORK:
*
# hash: 76f0ef591f999871e1dbdf6d5064d1276d80846feeef6b556f74ad87b44ca16a
You do need to be fully aware of standard browser caching. If the files in CACHE are in the network cache, they won't actually update, since the network cache will spit back the same file to the application cache. Therefore, it's recommended to add a hash to the filenames's, akin to rails or yeoman. See here why query strings are not recommended.
- 2012/10/23 - v0.4.0 - Changed package and repository name to grunt-manifest.
- 2012/10/23 - v0.3.0 - Upgraded to Grunt 0.4. Fixed dependencies. Fixed basePath.
- 2012/10/23 - v0.2.1 - Added possibility to manually specify "CACHE:" files. Made comments optional.
- 2012/09/28 - v0.2.0 - Refactored from grunt-contrib into individual repo.