grunt-keaton
v0.1.1
Published
Bust your assets via a hash change in a dedicated one liner version file.
Downloads
2
Readme
grunt-keaton
Bust your assets via a hash change in a dedicated one liner version file.
For example, load the hash from a version.txt and use it in your generated HTML in your assets paths:
<link rel="stylesheet" href="//assets.domain.tld/a253/css/base.css" />
<script src="//assets.domain.tld/a253/js/core.js"></script>
…
In the Apache conf for your assets subdomain:
RewriteRule ^/[^/]+/(.*)$ /$1 [PT,L]
Getting Started
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-keaton --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-keaton');
The "keaton" task
Overview
In your project's Gruntfile, add a section named keaton
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
keaton: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
});
Options
options.algorithm
Type: String
Default value: 'sha1'
Hash algorithm such as 'sha1'
, 'md5'
, 'sha256'
, etc.
Note that it must be available on your platform.
options.length
Type: Integer
Default value: 4
The length of the generated hash.
Usage Examples
Default Options
Using sha1 algorithm to generate a four character hash in ./version.txt
grunt.initConfig({
keaton: {
options: {},
files: {
src: ['version.txt']
},
},
});
Custom Options
Using md5 algorithm to generate a six character hash in ./static/version.txt
grunt.initConfig({
keaton: {
options: {
algorithm: 'md5',
length: 6,
},
files: {
src: ['static/version.txt']
},
},
});
Contributing
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.
Release History
(Nothing yet)