Assets Minification Salt and Pepper
Recently I discovered this awesome Laravel module to minify and aggregate assets.
My only issue was about generated hashes for aggregated files: as I had to distribute the files on different balanced servers I could not depend on mtime timestamps to salt them (as last git pull
time could slightly change on different servers), I could not leave the hashes depending only on original filenames (as they never change, and so did the hash, leaving rotting copies of the assets on the users' browser caches), so I had to leverage the useful hash_salt
explicit parameter in the Minify module configuration. The comment found in the configuration file itself wisely suggests to use the hash of the last commit, but provides no further instructions on how to modify it.
Solution: in the optimization script executed at each deploy of the application - the one providing Laravel cache refreshes and more - I've added the following two lines just before the php artisan config:cache
phase:
hash=`git rev-parse HEAD`
sed "s/'hash_salt' => '[a-z0-9]*',/'hash_salt' => '$hash',/g" config/minify.config.php -i