Code to optimize AngularJS for complex pages