Combine and minify js file using nodejs dynamically

I am new to nodejs and grunt.

I was going through the less-middleware and was very impressed with the way it automatically creates the css files. I now want the same for js files also. Let me briefly explain -

  1. User makes a request to site.min.js
  2. The routes automatically captures the particular request.
  3. Nodejs creates a new combined and minified js file based on the input parameters if the file is not already present.
  4. Return the combined file.

I feel grunt is not the right way to go about it since every time the js files are updated I will have to commit new version of the min file to the repo. I want some dynamic mechanism of creating the minified version.

Also not that i am trying to deploy my code on heroku.

Grunt will compile your js files during the build. I'm not aware of a runtime pull-and-minify for javascript.