How to automate javascript version increment if file has changed?

I use grunt to build a javascript/angularjs in the following order:

clean copy > uglify > cssmin .

Now, if I modify the js file, I always need to manually add the version increment at the end of the script tag so that the browser can detect the changes.

 <script src="/js/myscript?v123"></script> 

Question: how can I automate this process with grunt ? If I run the grunt command, only files that have changed from the last should receive a version increase. So that the browser can use cached files as much as possible.

+6
source share
1 answer

I know that short answers are out of order (not enough comments for comments), but you can check out grunt-asset-cachebuster . I have not tried it myself, but there are many examples on their npm page.

Also check out this answer about grunt-newer

+2
source

All Articles