6

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.

7
  • Are you using a server-side language, or is it plain html? Commented Dec 21, 2015 at 14:41
  • I'm using angularjs, thus javascript, css, html. Commented Dec 21, 2015 at 14:46
  • I'd appreciate an anwer to my quesiton more than a good wish, but thanks ;) Commented Dec 21, 2015 at 14:53
  • how big is your app(html, js, css) without libraries? If it is ~ 1Mb or less, I would advise to simply concat your app into single app.js and use cacheBust. Commented Dec 21, 2015 at 15:19
  • npmjs.com/package/grunt-assets-versioning Commented Dec 21, 2015 at 15:33

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

The plugin adds the timestamp to every file on compilation. I only want to add it on files that changed comparing to the last compilation. Apart from that it looks promising.
I have found a similar question. Checkout this answer: stackoverflow.com/a/19722900/2620998

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.