grunt-cache-bust
grunt-cache-bust copied to clipboard
Not always changing hash in files
Hi,
Sometimes the paths inside the files I've configured are not updating the hash.
Here is an example of one line inside an PHP file:
<script src="<?php echo __URL__; ?>/assets/js/scripts.min.1ba47e1224542500.js"></script>
This problem occurs after I've deleted the assets/js/scripts.min.1ba47e1224542500.js
file and executed the grunt task again. I've deleted it because sometimes (still haven't figured it out why) it creates more than one version of the file. To make it work again, I have to rename the filepath to <?php echo __URL__; ?>/assets/js/scripts.min.js
inside the PHP file and then run the grunt task again.
I'm using version 1.1.0 and this is my Gruntfile.js config:
cacheBust: {
taskName: {
options: {
deleteOriginals: true,
assets: [
'assets/stylesheets/*.min.css',
'assets/js/*.min.js',
]
},
src: [
'header.php',
'footer.php',
'index.php',
'example.php',
]
}
},
And my Grunt task:
grunt.registerTask('js', ['uglify', 'cacheBust']);
Any idea why this is happening?
When I run cacheBust with grunt watch
and then again with grunt js
, or vice versa, he is creating multiple files.
Hi @kossmann - sounds like you've run into a similar use cases as in #180. Have a read through the comments on there, especially the one about creating a clean copy of the code before running the task
Hi @hollandben I have similar issue. The problem is hash remain same on every time. If I run grunt task again and again but file name remain same. I use grunt-contrib-clean for cleaning publish directory first on each grunt build.
cacheBust: {
options: {
baseDir: 'public',
deleteOriginals: true,
jsonOutput: true
},
allAssets: {
options: {
assets: [
'publisher/*.js',
'publisher/*.css',
'admin/*.js',
'admin/*.css',
],
jsonOutputFilename: 'asset-fingerprints.json'
},
files: [{
expand: true,
cwd: 'public',
src: [
'publisher/*.html',
'admin/*.html'
]
}]
}
}
Is there any option for new hash on every bust?
Is there any option for new hash on every bust?
That's not the purpose of content hashing. The idea is that the files are hashed, giving you a unique string for the contents of that file. If you change 1 character in the file, then the hash will change. If you run the tasks 10 times without changing anything, then you'll get the same result everytime.
Thanks. Really appreciate your quick and detailed answer. I was trying to run task without changing content that’s why it was not updating.
@hollandben after update file references with the hashed url, this plugin recalculates the hash of the modified file again?
The process is this:
read files → generate hash → replace filenames → find and replace references
or this:
read files → generate hash → replace filenames → find and replace references → repeat all over until nothing changes
In case of the first (which I believe it is), I can work in the solution. Thank you!