Hello @denis-creative
Thank you for reaching out and I am happy to assist you with this.
Yes, you are correct when you say that after purging the cache, minify file names remain the same.
We do, however, have an option for that and it’s called “Prevent caching of objects after settings change” in Performance>Browser Cache.
You can set this option globally, or set it for the individual file types (HTML&XML, JS&CSS, Media&Other files).
What this option does is add a query string to a resource – ?xNNNNN
How this works in your case:
1. Minify is enabled and the files are cached:
https://yourwebsite.com/wp-content/cache/minify/02dfe.js
2. Enable “Prevent caching of objects after settings change” in Performance>Browser Cache, under the CSS/JS section, save all settings, and purge the cache.
3. If you check the website after that, you will see that the existing minified file has a random query string at the end:
https://yourwebsite.com/wp-content/cache/minify/02dfe.js?xNNNNN
4. The browser will fetch a new file version as it does not have the file with the query string cached.
5. If you make any changes in JS or CSS that are minified (or not), once the changes are done, go to either Performance>Browser Cache, or Performance>Minify and click on the Update Media query string button, just above the General sub-box, and make sure to save all settings and purge the cache after that
This will ensure that a new query string is generated and therefore force the browser to fetch the new version of the file from the server.
I hope this helps and let me know if you have any other questions.
Thanks!
Thank you very much.
I saw this solution to the problem.
But still the question is – why can’t the plugin generate new names for minified files every time after purging the cache?
Hello @denis-creative
Thank you for yoru feedback.
I understand that he would be beneficial for you, but not for other users.
As you may already know, there are different types of cache-busting:
- File name versioning (e.g. style.v2.css)
- File path versioning (e.g. /v2/style.css)
- Query strings (e.g. style.css?ver=2)
W3 Total Cache is using the Versioning with Query Strings, and the reason for this is that we want to ensure that the static files remain cached in Browser (1 year for static files is recommended). And this is where cache-control and expires header kicks in in the Browser Cache settings.
Generating a new file name every time the cache is purged would mean that every time Browser needs to fetch new files from the server, and therefore slows down the performance of the website.
For example, a JS-heavy website (themes and plugins) may have over 30 minified files. Imagine that every time the new product or article is added, and the cache is purged, new files also need to be fetched from the server.
Slow website – bad user experience.
I hope this explains why we use Query String versioning and please let me know if you have any other questions.
Thanks!
Thanks for the clarification, now it’s absolutely clear.