membersound
membersound

Reputation: 86727

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.

Upvotes: 6

Views: 1530

Answers (1)

Murat Ozgul
Murat Ozgul

Reputation: 11781

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

Upvotes: 2

Related Questions