Hey,
When CSS/JS files changed you don’t actually need to flush the cache directory. Flushing the cache directory won’t help anyway for old users if user does not press F5 or Ctrl+F5. Once F5 or Ctrl+F5 is pressed cached files are checked against current files (now changed) and are updated automatically.
You can, however, add a cache buster to the minify string by applying a filter to this hook: bwp_minify_get_src
, something like:
add_filter('bwp_minify_get_src', 'append_cache_buster');
function append_cache_buster($minify_string)
{
return $minify_string . '&ver=' . '1234567890';
}
I don’t understand the cache buster part – e.g. that it’s not updated if the source files change – aren’t you creating md5 based on the source css/js files date timestamps or checksums?
so if i have style.css and style1.css i have another checksum than when style1.css was being altered meanwhile? the ctrl+f5 idea is not a good solution
( i mean i understand it programmatically, but i thought bwp was taking care of file changes already )
Hey Khang,
Is it possible to adjust the filename of the generated css/js file based on the md5 checksum of the contents?
That way could push the css files to CDN without fearing for cache issues, and could drop the ?ver= parameters which are bad for frontend caching and micro cache proxies like varnish.
E.g. right now the .js result I get is this :
/cache/minify-b1-flexslider-684c1e3d23b06bc0b7d1a6d2ed4e90de.js?ver=1413915527
Once I change one of the files, it currently just changes the last part of the url ( the ver= part )
/cache/minify-b1-flexslider-684c1e3d23b06bc0b7d1a6d2ed4e90de.js?ver=1414633462
Any way to simply change the 684c1e3d23b06bc0b7d1a6d2ed4e90de checksum based on the file contents instead?
Changing the hash sounds like a good idea, however not possible at the moment. You can modify the code to achieve that (file includes/class-bwp-minify-fetcher.php
), for example:
$group_hash = md5($original_string . $detector_version . apply_filters('bwp_minify_build_number', ''));
and then add a filter at a suitable place.
Thanks Khang
I’ll review and send you a PR to github, so your future updates won’t overwrite those changes š
Have you ever got the chance to create a PR :)?