Skip to content

Instantly share code, notes, and snippets.

@stinoga stinoga/.htaccess
Last active Dec 20, 2015

Embed
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:
# 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>
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']);
};
<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
You can’t perform that action at this time.