sails.js Asset Versioning

If you are hosting from a git repository, you can use the git commit sha to identify version.

I use this approach in one of my projects, and it consists of adding the following as rename.js to tasks/config

var git = require('git-rev')

module.exports = function(grunt) {

  git.short(function(hash) {

    var files = {
      '.tmp/public/min/production.' + hash + '.min.js': '.tmp/public/min/production.min.js',
      '.tmp/public/min/production.' + hash + '.min.css': '.tmp/public/min/production.min.css'
    }

    grunt.config.set('rename', {
      dist: {
        files: files
      }
    })

  })

  grunt.loadNpmTasks('grunt-rename')

};

and then adding the rename task in tasks/register/prod.js just before the linker tasks.


Based on @CaseyWebb's solution we extended our sails app to address versioning issue with timestamp. There's also a very detailed blog entry about this here: https://naya.com.np/post/391862c0520b5b5632e99e812749a85b