file watcher - adding version name to file namef
已回答
Hi. The best practice to save asset files like css/js is to add the version name/number to the file name itself.
Example: index.v1.js
In the example, v1 represents the version, and so, I could change this to v2, and it would be unique file that the browser, would have to download, rather than using the existing cached file.
This is in contrast, to using query strings, like this:
index.js?v=1
which not all browsers will see as a unique file.
So, the question, is, how can I get file watcher to save the file name with a version name/number? And, if possible remove the old file.
请先登录再写评论。
Hi there,
File Watchers cannot do that.
I mean -- all what File Watcher plugin does (in simple words) it runs some program when file gets modified and saved in IDE. It cannot add any dynamic text like you want to the file name. If you wish -- write such program/script yourself and use it in a program field (yes, you can use any batch/shell file as a program in File Watcher .. and that batch file in turn can call any program inside it (e.g. a PHP script for example) that can generate such unique name etc .. so you can have complex logic inside it).
I guess you just need some build system. Something like Webpack .. perhaps. But it might be too complex for your needs. So self-made script will be a better solution in such case.
P.S. Instead of incremental v1, v2 you can use file modification timestamp (most common solution)... or file hash (MD5 for example).
I understand Andriy. I will create a custom bash script to run the commands I need. Thanks for your help!