0

I've read this post Mvc4 bundling, minification and AngularJS services

But it doesn't adress how to correctly minify AngularJS projects.

Should I minify everything except my viewmodels ? Lets say my templates use code like this:

 Hello <b>{{model.name}}</b>

if I minify the controller, the "model" property will be minified, right? Thus breaking the above template.

I saw some video about AngularJS where they stated that you can apply minification but skip minification for properties.

That should solve the problem, minify the code but keep all property names on controller/models

How would I accomplish this with MVC4 bundles?

Community
  • 1
  • 1
Roger Johansson
  • 22,764
  • 18
  • 97
  • 193

1 Answers1

3

I believe you can minify everything. You model will be always be instantiated over $scope such as $scope.myModel and hence the model names would not get minified.

What little bit i know about minification, a minifier does not minify elements that it cannot ascertain about their usage scope. So minifier minifies private vars, functions etc.

We are using AngularJS with bundler in our MVC project and we have not face issues with AngularJS as such.

Chandermani
  • 42,589
  • 12
  • 85
  • 88
  • So I only need to ensure my controllers have their dependency names mapped? e.g. .$inject(...); ? – Roger Johansson Jul 23 '13 at 09:43
  • 1
    Yes that is correct, but better would be to use the module type syntax that is mentioned in the SO post that you have mentioned. Something like `angular.module('mymodule', []).controller('MyController', ['$scope', function($scope){` – Chandermani Jul 23 '13 at 10:04
  • 1
    An this is required for every thing that uses AngularJS DI, this includes Controller, Service, Directive. – Chandermani Jul 23 '13 at 10:04