Busting cache with Grunt and Apache.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To understand why this is important and a better idea than `*.css?v231`, read: | |
# http://stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring | |
<IfModule mod_rewrite.c> | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L] | |
</IfModule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt) { | |
// Project configuration. | |
grunt.initConfig({ | |
// Replace object | |
replace: { | |
build_replace: { | |
options: { | |
variables: { | |
// Generate a truly random number by concatenating the current date with a random number | |
// The variable name corresponds with the same in our HTML file | |
'hash': '<%= ((new Date()).valueOf().toString()) + (Math.floor((Math.random()*1000000)+1).toString()) %>' | |
} | |
}, | |
// Source and destination files | |
files: [ | |
{ | |
src: ['public/index.html'], | |
dest: 'public/build/index.html' | |
} | |
] | |
} | |
} | |
}); | |
grunt.loadNpmTasks('grunt-replace'); | |
// Default task, you can obviously name this whatever you like | |
grunt.registerTask('default', ['replace']); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<!-- This variable corresponds with the var in our gruntfile --> | |
<script src="build/index.@@hash.js"></script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment