Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automate javascript version increment if file changed?

I'm using grunt to build a javascript/angularjs project in the following order:

clean copy > uglify > cssmin.

Now if I change a js file I'd always have to manually add a 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 using grunt? If I run the "grunt" command, only files that changed compared to the last run should get a version increment. So that the browser can reuse the cached files as much as possible.

like image 992
membersound Avatar asked Dec 21 '15 14:12

membersound


1 Answers

I know short answers are not OK (not enough rep to comment), but you might want to checkout grunt-asset-cachebuster. I haven't tried it myself but there are plenty of examples in their npm page.

Also checkout this answer about grunt-newer

like image 109
Murat Ozgul Avatar answered Oct 27 '22 18:10

Murat Ozgul