 				singleRun: true
 
 		'string-replace':
-			deploy:
-				files:
-					'<%= deployDirectory %>/<%= versionName() %>/index.html': ['<%= deployDirectory %>/<%= versionName() %>/index.html']
-					'<%= deployDirectory %>/<%= versionName() %>/index.debug.html': ['<%= deployDirectory %>/<%= versionName() %>/index.debug.html']
+			# This replacement treats src and href attributes which cannot contain variables in order for
+			# the minification process to work. It adds the applicationRoot tag variables before the files address.
+			commit:
+				files:
+					'<%= deployDirectory %>/<%= gitCommit %>/index.html': ['<%= deployDirectory %>/<%= gitCommit %>/index.html']
+					'<%= deployDirectory %>/<%= gitCommit %>/index.debug.html': ['<%= deployDirectory %>/<%= gitCommit %>/index.debug.html']
 
 				options:
 					replacements: [
-						pattern: /src="(\.\.\/)?(?!http|\/|\/\/|\#)/ig
-						replacement: 'src="/io/messages/'
+						pattern: /src="(\.\.\/)?(?!http|\/|\/\/|\#|\&|\'\&)/ig
+						replacement: 'src="' + tagApplicationRoot
 					,
-						pattern: /href="(\.\.\/)?(?!http|\/|\/\/|\#)/ig
-						replacement: 'href="/io/messages/'
+						pattern: /href="(\.\.\/)?(?!http|\/|\/\/|\#|\&|\'\&)/ig
+						replacement: 'href="' + tagApplicationRoot
 					,
 						pattern: '<script src="http://localhost:35729/livereload.js"></script>'
 						replacement: ''
+					]
+			# Here, all tag variables are replaced for production-ready endpoints.
+			version:
+				files:
+					'<%= deployDirectory %>/<%= versionName() %>/index.html': ['<%= deployDirectory %>/<%= versionName() %>/index.html']
+					'<%= deployDirectory %>/<%= versionName() %>/index.debug.html': ['<%= deployDirectory %>/<%= versionName() %>/index.debug.html']
+
+				options:
+					replacements: [
+						pattern: new RegExp(tagApplicationRoot, "gi")
+						replacement: '<%= applicationRoot %>/'
 					]
 
 		connect:


		if deployExists
			grunt.log.writeln 'Folder '.cyan + deployDir.green + ' already exists.'.cyan
			grunt.log.writeln 'Skipping build process and generating environmentType folder.'.cyan
			grunt.task.run ['clean', 'gen-version']
		else
			grunt.task.run ['prod', 'karma:deploy', 'copy:deploy', 'gen-version']

	#	Remote task
	grunt.registerTask 'remote', 'Run Remote proxy server', ->

	# Dist
	grunt.registerTask 'dist', ['prod', 'copy:dist']

	# Tasks for deploy build
	grunt.registerTask 'gen-commit', ['clean', 'copy:main', 'copy:test', 'coffee', 'less', 'copy:debug',
										'useminPrepare', 'concat', 'uglify', 'cssmin', 'usemin', 
										'copy:commit', 'string-replace:commit']

	# Generates version folder
	grunt.registerTask 'gen-version', ->
		grunt.log.writeln 'applicationRoot: '.cyan + grunt.config('applicationRoot').green
		grunt.log.writeln 'environmentName: '.cyan + grunt.config('environmentName').green
		grunt.log.writeln 'buildNumber: '.cyan + grunt.config('buildNumber').green
		grunt.log.writeln 'environmentType: '.cyan + grunt.config('environmentType').green
		grunt.log.writeln 'Version deploy directory: '.cyan + (path.resolve grunt.config('deployDirectory'), grunt.config('versionName')()).green
		grunt.task.run ['copy:version', 'string-replace:version']

	# Deploy - creates deploy folder structure
	grunt.registerTask 'deploy', ->
		commit = grunt.config('gitCommit')
		deployDir = path.resolve grunt.config('deployDirectory'), commit
		deployExists = false
		grunt.log.writeln 'Commit deploy directory: '.cyan + deployDir.green
		try
			deployExists = fs.existsSync deployDir
		catch e
