Skip to content

Instantly share code, notes, and snippets.

Last active December 20, 2015 10:49
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Busting cache with Grunt and Apache.
# To understand why this is important and a better idea than `*.css?v231`, read:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
module.exports = function(grunt) {
// Project configuration.
// 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'
// Default task, you can obviously name this whatever you like
grunt.registerTask('default', ['replace']);
<!-- This variable corresponds with the var in our gruntfile -->
<script src="build/index.@@hash.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment